Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Firestore: Missing or insufficient permissions

I am getting (on Android):

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

using these security rules:

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

My app seems to be properly authenticated using FirebaseAuth, as the mFirebaseAuth.getCurrentUser().getUid() returns the proper user ID.

Is there something I am doing wrong?

like image 482
Daniele B Avatar asked Nov 12 '17 05:11

Daniele B


1 Answers

Edit: just want to say that I managed to fix the issue by downgrading to 4.6.2. I have more details in this post

Pre-edit: This is happening to me ever since I upgraded react native and I cannot for the life of me figure out the problem. I've debugged it and my user is definitely authenticated at the time of the request, I checked this by running the below and I have a uid in there

firebase.auth().currentUser

So the next thing I wanted to do was check the session in the actual request to see what was happening. I added a piece of code to the entry point of my react app

XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
GLOBAL.originalXMLHttpRequest :
GLOBAL.XMLHttpRequest

and when I run this code it magically works again. This is delegating requests through the browser though so probably not a true test.

So then I started up Charles and compared the requests for my new react-native build with my old [working] react-native build. The requests look the same to me though (apart from a different sessionId) so I have no idea. The frustrating thing is the lack of debug tools through the firestore console.

My gut is to say some of the auth headers are expired/cached and that it's not firestore. Banging my head against a table at this point

like image 58
JamesR Avatar answered Oct 04 '22 02:10

JamesR