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
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,
This is because probably
Try this as temporary solution you may need to update it when added to production
Hopefully it works for you