Firebase Wildcard Security Rules
I have a data structure like this:
How can I access the value /Restaurant/-KK37k6g5cYYippEHpZ3/User/-KK37k6g5cYYippEHpZ4/id
in firebase security rules? The two button keys must be wildcards. I need something like this:
"Restaurant": {
"$id": {
".read": "auth.uid != null",
".write": "data.child($id).child('User').child($anotherWildcard).child('id').val() === auth.uid"
}
}
source to share
Not sure if I fully understood what you are asking for, but here are my thoughts.
The first problem with your rule is that you specify child($id)
, but you are already inside $id
. your data
implies what you mean $id
.
You don't need any other template to solve your main problem. You can just use hasChild
to check if is auth.uid
inside restaurant/user
.
"Restaurant": {
"$id": {
".read": "auth.uid != null",
".write": "auth.uid != null && data.child('User').hasChild(auth.uid)"
}
}
source to share