I'm trying to add security rules to my firebase application. But auth.uid is not working..
Here is two of my security rules..
"groups": {
"$groupid":{
".read" : true,
".write" : "root.child('groupmembers').child($groupid).child('admins').child(root.child('users').child(auth.uid).child('username').val()).val()==true"
}
},
"groupchat":{
"$chatid":{
".read" : "root.child('groupmembers').child($chatid).child('members').child(root.child('users').child(auth.uid).child('username').val()).val()==true",
".write" : "root.child('groupmembers').child($chatid).child('members').child(root.child('users').child(auth.uid).child('username').val()).val()==true"
}
}
On the first rule auth.uid is working.. But in case of second and rest other rules, auth.uid is not working at all. I added my original uid in place of auth.uid and all rules are working properly.
Client side operation example..
Map<String, Object> map = new HashMap<String, Object>();
map.put("username", userid);
map.put("message", userid + " Created This Group.");
map.put("timestamp", ServerValue.TIMESTAMP);
map.put("zcode",chat_key);
map.put("type", "action");
FirebaseDatabase.getInstance().getReference()
.child('groupchat')
.child(groupid)
.push()
.updateChildren(map);
Users Structure
"users":{
"my_uid" : {
"email" : "[email protected]",
"username" : "user1"
}
}
groupmembers structure
"groupmembers":{
"groupid":{
{
"admins" : {
"user1" : true,
"user3" : true
},
"members" : {
"user1" : true,
"user2" : true,
"user3" : true,
"user4" : true
}
}
}
}
So how can I solve this problem?