Open When - An Expo + Firebase Firestore Platform

I was able to fix doing the following:

  • Downgrading to firebase 7.9.0 (newer versions seem not to be fully compatible with expo)
  • using these import statements and initializations
import * as firebase from 'firebase'
import "firebase/firestore"
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
1 Like

I had the same problem, but the solution it isn’t downgrading the version for the firebase package. Searching on the internet and other people with the same error, I was found these:

  • The firefire firebase does not show any error messages and finding a solution is very difficult
  • The default configuration on firestore put false the condition rules for security, and this is the real problem.

Finally, the solution is changing the rule on the firestore.

rules_version = ‘2’;
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if TRUE # change FALSE for TRUE
}
}
}

Expo + Firestore has become my go-to stack for all apps. I’ve built a number of libraries/products around it. In case it’s useful for anyone here:

1 Like

you need to parse the response using .then() or async await as such ;-

const getUser = async () => {
      const currentUser = await dbh
        .collection("users")
        .doc(firebase.auth().currentUser.uid)
        .get();

      if (currentUser) {
        const data = await currentUser.data();
        console.log("Logged in as ", data);
      }
    };

@ccheever Its not working… error saying firebase.database() is not a function

Is it possible to use offline persistence with firebase v9?