skip to Main Content

My Firestore read requests are getting errored out. I believe that some sort of incorrect blacklisting has happened.

Environment: development

Purpose: To find a document in my Firestore collection named "auth"

Firestore rules:

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

Firestore Schema:

Collection name: auth
Document: <email id> eg: [email protected]
Fields: name, role

Code:

let docRef = doc(db, "auth", newUserEmail.value); // <email id>
let docSnap;
try {
docSnap = await getDoc(docRef);
} catch(error) {
console.log("error: ", error);
}

Error message:
error: FirebaseError: Missing or insufficient permissions.

I get the same error message irrespective of whether the document that I’m looking up is present or not.

Finally, I’m not sure how to go about troubleshooting as Firestore has no logging system visible to developers and there are no flags on my web console.

2

Answers


  1. Chosen as BEST ANSWER

    Based on inputs from @Doug, I realized that my rules were not permitting requests from unauthenticated users in the new login/registration pages which was exactly where the issue occurred.

    I've updated my rules to,

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

  2. This is because probably

    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if request.time < timestamp.date(2023, 12, 17);
        }
      }
    }  
    

    Try this as temporary solution you may need to update it when added to production

    Hopefully it works for you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search