Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore security rules get function error

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.

  • Security rule
  • The database

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.

like image 610
Nándor Szűcs Avatar asked Apr 29 '26 06:04

Nándor Szűcs


1 Answers

I solved my problem with the following configuration: enter image description here

You have to setup a real Firebase UID to use the simulator, the actual UID solved the problem, the error message was very misleading.

like image 65
Nándor Szűcs Avatar answered May 02 '26 21:05

Nándor Szűcs