I have a firebase realtime database. Currently it contains two nodes admin
and common
{
"admin" : {
"adminval" : 9898574632,
"adminval1" : 645354536,
"adminval2" : 7776756433
},
"common" : {
"commonval" : 123433221
}
}
I added to each user custom claim roles
which describes roles user has in my system. It looks like this
{'roles': ['ROLE_ADMIN', 'ROLE_USER']}
Now I would like to restrict access so only users with claim ROLE_ADMIN
are allowed to read/write admin
node and with either of the roles can read/write node common
.
How to do it ? I tried something like it:
{
"rules": {
"admin": {
".read": "auth.token.roles.contains('ROLE_ADMIN')",
".write": "auth.token.roles.contains('ROLE_ADMIN')"
}
"common": {
".read": "auth.token.roles.contains('ROLE_USER') || auth.token.rules.contains('ROLE_ADMIN')",
".write": "auth.token.roles.contains('ROLE_USER') || auth.token.rules.contains('ROLE_ADMIN')"
}
}
}