Monu
Monu

Reputation: 907

Firestore unable to access data - Missing or insufficient permissions

Problem:

Firestore not returning data and giving exception "PERMISSION_DENIED: Missing or insufficient permissions"

Rules:

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

Android Code:

firestore.collection("todos").document("t2").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                Log.d(TAG, "E1:" + task.getException().getMessage());
            }
        });

Database:

enter image description here

Working:

  1. Firebase authentication is working fine.
  2. Firebase Realtime Database is also working fine.

Things I tried:

  1. It says firestore rule can take some time to take effect, so I waited around 24 hours but still no result.
  2. I tried rules playground and it says data is readable enter image description here
  3. Tried creating new android app and adding in project, still same problem with new app.

Please tell me what I might be missing. As firebase google authentication is working fine, I can say my app is communicating with firebase and SHA-1 is also right. I found other similar questions too, but all says to change rules, which already flexible as possible. I know my rules are insecure, I just want to communicate with database to make sure everything is right.

Upvotes: 1

Views: 234

Answers (1)

Monu
Monu

Reputation: 907

Finally after wasting several hours, creating multiple projects and multiple apps, my problem got solved, and solution is very weird.

Google account on which I was creating these projects was relatively new and even though I was creating new projects I was getting same results. Then I created project using my old Google account which I used in past for firebase, and it started working fine.

I don't know why this happened. I don't think reason is related to bank verification because my project was just started and in free tier, and all other features were working fine. May be this was bug in firebase.

Upvotes: 1

Related Questions