Firestore: PERMISSION_DENIED: Missing or insufficient permissions

I get an error

gettingdocuments.com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.

for the code below in an else statement

db.collection("users")
        .get()
        .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                 if (task.isSuccessful()) {
                     for (DocumentSnapshot document : task.getResult()) {
                         s(document.getId() + " => " + document.getData());
                     }
                 } else {
                     s("Error getting documents."+ task.getException());
                 }
             }
         });
+44
source share
8 answers

Note: this completely disables the security of the database, making it writable without authentication !!! This is NOT a solution to recommend.

It just works for me.

Go to the database → Rules ->

Change allow read, write: if false; to the truth;

+57
source

Go to the databaseRules :

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

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

, ,

+4

:

service cloud.firestore {
  match /databases/{database}/documents {
    match /stories/{story} {
      function isSignedIn() {
        return request.auth.uid != null;
      }

      allow read, write: if isSignedIn() && request.auth.uid == resource.data.uid
    }
  }
}

, story uid .

():

Firestore.instance
          .collection('stories')
          .snapshots()

, . , :

Firestore.instance
          .collection('stories')
          .where('uid', isEqualTo: user.uid)
          .snapshots()

: https://firebase.google.com/docs/firestore/security/rules-query

+4

, , firebase.

, firebase - users, db.collection("Users") db.collection("user")

.

, -

+1

Java Swing Application.

  1. Firebase> >

  2. " " " ".

  3. .json,
  4. " ", " ", " ".
  5. "GOOGLE_APPLICATION_CREDENTIALS" json.
+1

. , :

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

  : ( ) . , , !

→ ->

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}
-2

Source: https://habr.com/ru/post/1686977/


All Articles