Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In react native app (through Expo) using firestore permissions - request.auth is always null

Here's my code:

firebase.auth().onAuthStateChanged((user) => {
    if (user) {
        console.log("We are authenticated now!");
        firebase.firestore().collection("users")
            .doc(firebase.auth().currentUser.uid).set({ name: "new name" });
    } else {
        loginWithFacebook();
    }
});

And, here are my permission rules:

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

It seems like no matter what, request.auth is always null. The error I get:

Firestore (4.8.0) 2017-12-20T04:18:27.321Z [Connection]: WebChannel received error: {"code":403,"message":"Missing or insufficient permissions.","status":"PERMISSION_DENIED"}

like image 392
Ronen Rabinovici Avatar asked Dec 17 '17 20:12

Ronen Rabinovici


1 Answers

I downgraded to Firebase SDK 4.6.2 when I had this problem with latest Firebase JS SDK on Expo.

Also, you have to do this in order for everything to work:

Copy https://gist.githubusercontent.com/mikelehen/444950a35019208f3aaf18d37ab4937c/raw/85ac4cb3108d92163cb8f04fbdddcc88d4081aab/index.js

over your node_modules/@firebase/webchannel-wrapper/dist/index.js

Without this, you'll get nothing from your collections.

Hope this helps.

like image 190
Igor Avatar answered Nov 15 '22 23:11

Igor