Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Firestore requests are erroring out with status: FirebaseError: Missing or insufficient permissions.

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.
Solved Solved
1 7 7,273
1 ACCEPTED SOLUTION

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;
    }
  }
}
 

View solution in original post

7 REPLIES 7

julien_bisconti
Google Developer Expert
Google Developer Expert

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());
});

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.

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;
    }
  }
}
 

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;
    }
  }
}

Can you provide some screenshots for context? The configuration seems fine, are there any error messages that you see?

Yes. I send some pictures below (successfully message, my rules, result on GG firestore).

hn00_1-1697597774687.png

hn00_2-1697597795488.png

 

hn00_0-1697597746871.png

hn00_3-1697597803023.png

 

hn00_4-1697597873340.png

This is my rules