I'm trying to develop a simple Chat app using Firebase platform. To show a list of conversations I'm using FirebaseRecyclerAdapter. The thing is, that I can't figure out how to properly set the rules so users can only access conversations, that they are members of.
This is what my Firebase DB structure looks like.
{
"conversations": {
"cid1": {
"title": "Conversation1"
},
"cid2": {...
},
"cid3": {...
}
},
"members": {
"cid1": {
"uid1": true,
"uid2": true
},
"cid2": {...
},
"cid3": {...
}
},
"users": {
"uid1": {
"name": "User1"
},
"uid2": {...
},
}
}
And these are the rules I'm trying to apply.
{
"rules": {
"conversations": {
"$conversation_id": {
".read": "root.child('members').child($conversation_id).child(auth.uid).exists()",
}
},
}
}
By applying this rules and using FirebaseRecyclerAdapter I'm getting this error.
Listen at /conversations failed: DatabaseError: Permission denied
I suppose it's because I'm allowing users to read to conversation element, but not the whole list of conversations. Anybody has an idea how to solve this problem?