Flutterfire: [cloud_firestore] request.auth will be null when using getDocuments()

Created on 21 Mar 2020  路  4Comments  路  Source: FirebaseExtended/flutterfire

Describe the bug
I'm setting security rule like this

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

When I get data from fireStore using .getDocuments exception PlatformException (PlatformException(Error performing getDocuments, PERMISSION_DENIED: Missing or insufficient permissions., null)) will be throw
snapshots().listen doesn't throw error and get data

To Reproduce
Steps to reproduce the behavior:

  1. Set Security rule as
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
  1. get data from fireStore using .getDocuments
  2. error will be throw

Expected behavior
can get data list using security rule

bug

Most helpful comment

Your link returns 404. I think this is what you mean: https://firebase.google.com/docs/firestore/security/rules-structure#recursive_wildcards
Solved the issue for me too

All 4 comments

Sorry
I think it was my fault

What were you doing wrong? I think I'm having the same or similar issue

I don't know the critical solution but I think I missed the rule of path
I fixed it to wild rules and passed the rules.

https://firebase.google.com/docs/firestore/security/secure-data?hl=us#recursive_matching_with_wildcards

Your link returns 404. I think this is what you mean: https://firebase.google.com/docs/firestore/security/rules-structure#recursive_wildcards
Solved the issue for me too

Was this page helpful?
0 / 5 - 0 ratings