firebase - How to write a security rule for common membership -


i trying create security rule allows user in group read information of other user in same group. in other words user should able read user information of user belongs common group.

this have:

{   "rules": {     "users": {       "$user_id": {         // user beloging @ least 1 group in common should able read         ".read": "$user_id === auth.uid || root.child('users/' + $user_id + '/groups').hasany(root.child('users/' + auth.uid + '/groups'))",         ".write": "$user_id === auth.uid",          "groups": {           "$group_id": {             ".validate": "root.child('groups/' + $group_id).exists() && newdata.isboolean()"           }         }         }     },      "groups": {       "$group_id": {         "name": { ".validate": "newdata.isstring() && newdata.val().length > 0 && newdata.val().length < 50" }       }     },      "members": {       "$group_id": {         ".read": "root.child('members/' + $group_id + '/' + auth.uid).exists()",         ".validate": "root.child('groups/' + $group_id).exists()",         "$user_id": {           ".write": true, // skipped brevity           ".validate": "root.child('users/' + $user_id).exists() && newdata.isboolean()"         }       }     },     }   } } 

of course, hasany function not part of api. there way existing api? there plans add this?

to maintain user's friends list.

you'll have keep reference of user's friends list. when user join group, add group member's auth.uid user's friends list. then, friends can read profile.

{"rules":{   // $user_id == current user's auth.uid   // $friend_id == friend's auth.uid   // $member_id == group member's auth.uid   "users":{"$user_id":{     "friends":{"$friend_id":{     }},      // readable friends:     ".read":"auth =! null && data.child('friends').haschild(auth.uid)"    }},   "groups":{"$group_id":{     "members":{"$member_id":{     }}   }} }} 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -