My Firestore read requests are getting errored out. I believe that some sort of incorrect blacklisting has happened.
Environment: development
Purpose: To get a list of all documents 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;
}
}
}
Code:
let docRef = doc(db, “auth”, newUserEmail.value);
let docSnap;
try {
docSnap = await getDoc(docRef);
} catch(error) {
console.log("error: ", error);
}
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.
1 Like
Could you please share the error message ? It might help diagnose the cause.
To list all documents in a collection:
const citiesRef = db.collection('cities');
const snapshot = await citiesRef.get();
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
1 Like
Hi Julien, this is my error message,
index-00398238.js:1 FirebaseError: Missing or insufficient permissions.
But I get a 200 response for my Firebase Firestore requests.
Also, I get the same error message irrespective of whether the document that I’m looking up is present or not.
Hope this is sufficient information.
1 Like
Based on inputs from the community, 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;
}
}
}
1 Like
I tried to do that. But It’s not changed on the remote. It still keep the default value.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
1 Like
Can you provide some screenshots for context? The configuration seems fine, are there any error messages that you see?
2 Likes
Yes. I send some pictures below (successfully message, my rules, result on GG firestore).
1 Like