Home > Software engineering >  getting username and email from firestore in reactnative mobileapplication
getting username and email from firestore in reactnative mobileapplication

Time:12-06

I want to get current login username and email from firestore, but it throws an error.

The code:

firestore()
  .collection('users')
  .get(firebase.auth().currentUser.uid)
  .then(querySnapshot => {
    querySnapshot.forEach((doc) => {
      console.log(doc.id, " => ", doc.data());
    })
  });

I write this code and it throws an error:

Error: firebase.firestore().collection().get(*) 'options' must be an object is provided., js engine: hermes

CodePudding user response:

you are passing an invalid argument to get() method

get(options?: GetOptions): Promise<DocumentSnapshot<>>;

GetOptions type

{
   source: "default" | "server" | "cache";
}

ref: https://rnfirebase.io/reference/firestore/documentreference#get

CodePudding user response:

If you want to load a single document based on the user ID, that'd be:

firestore()
  .collection('users')
  .doc(firebase.auth().currentUser.uid)
  .get()
  .then(doc => {
    console.log(doc.id, " => ", doc.data());
  });

The change here is that we pass the UID to a function called doc() to build a reference to the correct document, and we then call get() on that document reference without any arguments.

  • Related