My Firebase data structure looks like
-isAdmin
-user1
isAdmin: true
-users
-user1
-firsName: Jane
-lastLoggedIn: 12 March 2017
-user2
-firstName: John
-lastLoggedIn: 11 March 2017
I want my admin (user 1) to be able to do the following
Add more users to -users branch. So I need the following permission (to create user3, user4...etc)
"users": {
.write: "(auth != null) && (root.child('isAdmin').child(auth.id).val == true)
}
However I also want the non-admin user to be able to update the lastLoggedIn Entry. So I need the following permission
"users": {
$userId: {
"lastLoggedIn": {
.write: "(auth != null) && ($userId == auth.id)
}
}
}
Here is the problem though, firebase does not allow nested rules, since I have a .write rule under users, the .write rule under users/$userId/lastLoggedIn will be ignored I believe
Is there a way to get around this problem?