"RegisterRequests": {
"$uid": {
".write": "$uid === auth.uid && !root.child('Users').child(auth.uid).exists()",
".validate": "newData.hasChildren(['Nickname']) && newData.hasChildren(['Whatever'])",
"Nickname": {
".validate": "newData.val().length > 1 && newData.val().length < 17 && !root.child('Users').child('Nickname').child(newData.val()).exists() && !root.child('RegisterRequests').child('Nickname').child(newData.val()).exists()"
},
"Whatever": {
".validate": "newData.val() > 0 && newData.val() < 6"
},
"$other": { ".validate": false }
}
}
"Users": {
"$uid": {
".read": "$uid === auth.uid",
"Nickname": {
}
}
}
These are my rules for my database. I am trying to prevent adding data that contains a nickname already existing in Users
or RegisterRequests
. I think I fail here: !root.child('Users').child('Nickname').child(newData.val()).exists() && !root.child('RegisterRequests').child('Nickname').child(newData.val()).exists()
because Nickname
has value not children. But I don't know how to make this check. Also I don't know if this is a correct way to check for children anyway, because I am missing the Identifier child in this hierarchy. Can anyone help me?