When a user signs up, the application saves the user in Firestore with the same uid generated for Firebase authentication. Now I am trying to write a security rule for a separate collection (not the user collection) where read and write operations are allowed to the requester only if that requestor has the isAdmin field set to true. As you can see on the images, even when the path is correct in the get() function, I got a non-existent error. What could cause this error?
I tried many variations of the path, changing collection, lowercase everything etc. I could not find anything about this in Google and the official documentation shows the usage the same way I use it.
The security rule:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /user/{user} {
allow read,write: if true
}
match /akarmi/{akarmiId} {
allow read, write:
if get(/databases/$(database)/documents/user/$(request.auth.uid)).data.isAdmin == true
}
}
}
I expect this code to run and allow or disallow acces and not throw a nonexistent error.
request.auth.uid
into[ ]
? Like this:if get(/databases/$(database)/documents/user/$([request.auth.uid])).data.isAdmin == true
– Constantin Beer