android - Firebase Database: add rule to find a particular value out of all childs -
i want setup security rules database , want users , admins read particular group, rules don't work.
the work when set specific index. don't know how can check indexes. possible in way?
rules:
{ "rules": { "groups": { "$groupid": { ".write": "!data.exists()", ".read": "data.child('users').child('$index').val() == auth.uid || data.child('admins').child('$index').val() == auth.uid" } }, "users": { "$uid": { ".read": "auth != null", ".write": "$uid === auth.uid" } } } }
i suggest change database structure this. put user's id child key of users
, admins
{ "groups": { <groupid1>: { "admins": { <uid1>: true, <uid2>: true }, "description": "some description", "users": { <uid3>: true, <uid4>: true, <uid5>: true }, ... }, <groupid2>: { ... } } }
then database rules job
{ "rules": { "groups": { "$groupid": { ".write": "!data.exists()", ".read": "data.child('users').child(auth.uid).val() == true || data.child('admins').child(auth.uid).val() == true" } } } }
hope helps :)
Comments
Post a Comment