In my DB I have "users" and those users have a variety of nodes attached to them. I want some nodes to be available, and some to be hidden.
{
"rules": {
"users": {
"$userId": {
"dateOfBirth": {
".read": "auth != null",
".write": "$userId === auth.uid"
},
"gender": {
".read": "$userId === auth.uid",
".write": "$userId === auth.uid"
},
The above makes logical sense to me but it doesn't work - the user can't gain access to the "$userId" layer, which it needs to be able to access the rest of the nodes. However, if I add a "read" entry to the "users" level, it overwrites any attempts to deny access at a lower level, for "gender" for example.
{
"rules": {
"users": {
".read": true // Added this
"$userId": {
"dateOfBirth": {
".read": "auth != null",
".write": "$userId === auth.uid"
},
"gender": {
".read": "$userId === auth.uid",
".write": "$userId === auth.uid"
},
To even reach the dateOfBirth of a different user, their user ID has to be read. So I need to give permission to read the user ID whilst allowing the lower down rules to still take effect.