Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Firestore missing or insufficient permissions using Expo (React Native)

I've been using FireStore for a project that works fine in the browser, but when I port the code to Expo, running on a iOS 11.2 iPhone X in the simulator, it keeps raising Error: Missing or insufficient permissions.

Auth is working fine, and when I check the client in the Firestore collection object, the appropriate UID is set, and testing the same code in the browser, everything works perfectly (no permissions problem). What I'm trying to say is that I'm 95% certain that the issue is with the Firebase lib/react native/expo combination, rather than with my code. Especially since it seems that making a call to Firestore in the browser, there are headers set, but when debugging the call in Reactotron (from Expo), it looks like the call the Firebase lib is making has no headers at all.

I doubt it makes a difference, but here are my auth rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /UserData/{userID} {
      allow read, write: if request.auth.uid == userID;
    }
    match /MemberData/{userID} {
      allow read: if request.auth.uid == userID;
    }
  }
}

The call I was trying to make (and there is definitely data in the doc) is the following:

profile = (await UserDataCollection.doc(`${idToken.uid}`).get()).data();

I'm curious if anyone else has run into this problem, and if so, are there any workarounds to make Firestore work?

like image 468
raphaeltm Avatar asked Jan 02 '18 02:01

raphaeltm


1 Answers

As per previous comments, downgrading to 4.6.2 seems to fix the issue. I'm not sure the exact root cause but the behaviour of how the auth headers are sent seem to have changed (so potentially something there?). I'll update my answer if I get time to investigate further. Happy for one of the Firebase team to contact me for my account details if they want to verify on their side.

like image 63
JamesR Avatar answered Oct 21 '22 21:10

JamesR