Here is very simple rule for users:
{
"rules": {
"users": {
".read": true,
"$userId": {
".write": "auth.uid === $userId"
}
}
}
}
Of course it's not working when we want to create new user, and here is my question, how to create rule which will be checking if new key in users
path will be the same as auth.uid
?
Update
I need something like this line ".write": "auth.uid === $userId"
below ".read": true
but here is impossible because it wouldn't see $userId
variable.
In my case this should work:
/users
{ "user1" : { "name": tester" } }
user1
but this shouldn't:
/users
{ "user1" : { "name": tester" } }
user2
答案 0 :(得分:0)
{
"rules": {
"users": {
".read": true,
".write": "newData.hasChild(auth.uid) || data.hasChild(auth.uid)",
"$userId": {
".write": "auth.uid === $userId"
}
}
}
}