skip to Main Content

For the sake of testing, my rules are as open as possible:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write, create: if true;
    }
  }
}

I make a call from Flutter to the Firebase Emulator

final bookDoc = await FirebaseFirestore.instance.collection('books').doc(bookId).get()

and I get this error:

FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.)

This happens only on the emulator. Making the same call to the Firebase server works fine.

I tried calling other documents in other collections, and verified that these documents exist.

I had a past attempt to configure AppCheck, but I removed it – from pubspec, removed the initialize function, from Android app/build.gradle. Might there be some other left over that I don’t know of?

Any other direction I should look into?

2

Answers


  1. Chosen as BEST ANSWER

    OK, this is embarrassing.

    I had these in my emulator initialization:

    FirebaseFunctions.instance.useFunctionsEmulator('127.0.0.1', 5001);
    FirebaseAuth.instance.useAuthEmulator('127.0.0.1', 9099);
    

    So I saw functions affecting emulator logs, and rule updates appearing in emulator logs, but I mistakenly deleted:

    FirebaseFirestore.instance.useFirestoreEmulator('127.0.0.1', 8080);
    

    I hope it helps someone else who makes this silly mistake.


  2. same error [firestore/permission-denied] The caller does not have permission to execute the specified operation.
    

    I already changed firestore.rules in every way

    {
      "firestore": {
        "rules": "firestore.rules",
        "indexes": "firestore.indexes.json"
      },
      "functions": [
        {
          "source": "functions",
          "codebase": "default",
          "ignore": [
            "node_modules",
            ".git",
            "firebase-debug.log",
            "firebase-debug.*.log"
          ],
          "predeploy": ["npm --prefix "$RESOURCE_DIR" run lint"]
        }
      ],
      "storage": {
        "rules": "storage.rules"
      },
      "emulators": {
        "functions": {
          "host": "192.168.1.5",
          "port": 5001
        },
        "firestore": {
          "host": "192.168.1.5",
          "port": 8080,
          "rules": "firestore.rules"
        },
        "storage": {
          "port": 9199
        },
        "ui": {
          "enabled": true
        },
        "singleProjectMode": true,
        "auth": {
          "host": "192.168.1.5",
          "port": 9099
        }
      }
    }
    
    rules_version = '2';
    service cloud.firestore {
        match /databases/{database}/documents {
    
            match /users/{userId} {
                allow read, write: if true;
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search