0
votes

I have the following document

The firesotre document

and I have set the following rules

The firestore rules

Every time I try to read the document using the Android SDK

FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("users").get().addOnCompleteListener(appExecutors
                     .networkIO(),
             task -> {});

I am getting this error

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

I am not sure what is wrong is it the rules or the Android call.

4

4 Answers

4
votes

It looks like you meant to type resource.data.author_id instead of resource.data.author_d in the rule.

0
votes

This code is trying to access every document in the entire users collection:

db.collection("users").get()

If there any any document in that collection that violates the security rules you set up, then it will fail.

Did you instead intend to try to access the single document that the user is supposed to have access to?

0
votes

I think you can fix this from firebase consol. You just need to sllow access to all user. As I remember by default there was allowed only authorized users.

0
votes

It seems that I had to add a where close in my code

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    FirebaseFirestore.setLoggingEnabled(true);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    db.collection("users").whereEqualTo("authorId",user.getUid()).get().addOnCompleteListener(appExecutors.networkIO(),task -> {});