To support multiple profiles.
The following answer creates several profiles / profile views for each group that the user joins. Like several resumes that you send about yourself to different companies. Thus, company members may know you differently depending on the resume you sent them.
Each of the user profiles is available only to members of the assigned group.
When the auth.uid viewer is a member of the barney group, the viewer can view all users who have profile/barney recorded in his account.
{"rules":{ // $user_id == current user auth.uid // $friend_id == his friend auth.uid // $member_id == group member auth.uid "users":{"$user_id":{ "profile":{"$group_id":{ // readable by group members: ".read":"auth =! null && root.child('groups').child($group_id).child('members').hasChild(auth.uid)" }} }}, "groups":{"$group_id":{ "members":{"$member_id":{ }} }} }}
source share