admin管理员组

文章数量:1401171

I have these firebase rules

service cloud.firestore {
  match /databases/{database}/documents {
    match /anizations/{anizationId} {
      allow create: if request.auth.token.superUser == true;
      allow read, write: if request.auth != null && request.auth.uid in request.resource.data.userIds;

and a listener like this

FirebaseFirestore.instance
          .collection(ORGANIZATIONS_PATH)
          .where('userIds', arrayContains: userId)
     
          .snapshots()
          .handleError((onError) {
            print('Org Service: naizations listener error');
            print(onError);
          })
          .listen(_onOrganizationsChanged);

The documents show up as expected, but I'm also getting this error from the error handler:

the caller does not have permission to execute the specified operation.

How can I resolve this? Is it a bug that I'm both getting the documents and an error saying that he operation is not allowed?

I have these firebase rules

service cloud.firestore {
  match /databases/{database}/documents {
    match /anizations/{anizationId} {
      allow create: if request.auth.token.superUser == true;
      allow read, write: if request.auth != null && request.auth.uid in request.resource.data.userIds;

and a listener like this

FirebaseFirestore.instance
          .collection(ORGANIZATIONS_PATH)
          .where('userIds', arrayContains: userId)
     
          .snapshots()
          .handleError((onError) {
            print('Org Service: naizations listener error');
            print(onError);
          })
          .listen(_onOrganizationsChanged);

The documents show up as expected, but I'm also getting this error from the error handler:

the caller does not have permission to execute the specified operation.

How can I resolve this? Is it a bug that I'm both getting the documents and an error saying that he operation is not allowed?

Share Improve this question edited Mar 24 at 2:45 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges Recognized by Google Cloud Collective asked Mar 24 at 1:39 xerotolerantxerotolerant 2,0794 gold badges25 silver badges46 bronze badges 5
  • 1 My guess is that you're seeing results from the local cache, which were written there before you tightened your security rules. On Android, deinstall and reinstall the app to clear the cache. On iOS wipe the app data too. – Frank van Puffelen Commented Mar 24 at 2:51
  • Have you solved the issue? – Alex Mamo Commented Mar 24 at 7:23
  • @FrankvanPuffelen I ran flutter clean and rebuild the app (for macOS) but the errors persist. Is there an additional step to 'clearing the cache' on macOS besides 'flutter clean' and 'product -> clean build folder' in Xcode? – xerotolerant Commented Mar 24 at 13:00
  • @AlexMamo I have not. I just realized on web that I'm not getting the data at all now. So the issue might be with the permissions themselves. Not sure why I would get the data on MacOS and not web. – xerotolerant Commented Mar 24 at 13:30
  • I am not at all sure why changing the order of the rules worked but the errors have gone away so yeah. – xerotolerant Commented Mar 24 at 13:42
Add a comment  | 

1 Answer 1

Reset to default 0

I'd be lying if I said I know WHY this worked but I rearranged the rules to this

rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {

    match /user_profiles/{userId} {
      allow read: if request.auth != null;
    }
    
    match /{document=**} {
      allow read, write: if request.auth.token.superUser == true;
    }

    match /anizations/{anizationId} {
      allow read, write: if request.auth != null && request.auth.uid in resource.data.userIds;

      match /{document=**} {
        allow read, write: if request.auth.uid in (get(/databases/$(database)/documents/anizations/$(anizationId))).data.userIds;
      }
    }
  }
}

本文标签: flutterFirestore says operation is not permitted but still returns documentsStack Overflow