Reputation: 19275
My database has the structure:
users
User_ddac15a6-1890-43d8-9bfb-a13e9b99499e
...
That is a user's folder is of the format 'User_'+$user_id
I'm trying to set rules as follow:
{
"rules": {
"users": {
"User_$user_id": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
}
}
}
But when trying to save the rules I get:
9:7: Key names can't contain ".", "#", "$", "/", "[", or "]" (unbound names start with "$")
How can I set security rules on such a folder names structure ?
Upvotes: 1
Views: 841
Reputation: 598728
You cannot put the $ sign in the middle of a rule name, it must be at the start. But you can get the desired result like this:
{
"rules": {
"users": {
"$user_id": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".read": "$user_id === ('User_'+auth.uid)",
".write": "$user_id === ('User_'+auth.uid)"
}
}
}
}
Upvotes: 3