Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firestore: PERMISSION_DENIED: Missing or insufficient permissions

I am getting the Error

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

for the below code on 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());              }          }      }); 
like image 288
SUHAS REKHU Avatar asked Oct 05 '17 16:10

SUHAS REKHU


2 Answers

Go in Database -> Rules ->

For development:

Change allow read, write: if false; to true;

Note: It's quick solution for development purpose only because it will turns off all the security. So, it's not recommended for production.

For production:

If authenticated from firebase: Change allow read, write: if false; to request.auth != null;

like image 151
Luvnish Monga Avatar answered Sep 22 '22 21:09

Luvnish Monga


Go to Database -> Rules :

Then changed below rules

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

to below

service cloud.firestore {   match /databases/{database}/documents {     match /{document=**} {       allow read, write: if request.auth != null;     }   } } 
like image 43
Md Nakibul Hassan Avatar answered Sep 21 '22 21:09

Md Nakibul Hassan