I am trying to write some simple firebase rules that will only allow the authenticated user to be able to write over their data.
{
"rules": {
"users": {
"uid": {
".read": true,
".write": "auth != null && auth.uid == uid"
// unknown variable uid.
}
}
}
}
for some reason, I keep getting error above. The uid is inside so I don't get why there is a error?
To declare a wildcard capture variable the name of the node needs to start with a $
. So:
{
"rules": {
"users": {
"$uid": { // 👈 add $ here
".read": true,
".write": "auth != null && auth.uid == $uid" // 👈 now you can use the variable here
}
}
}
}