unable to get data from fireStore React Native Expo

Viewed 179

I tried to fetch data from FireStore like this:

async function getUserInfo() {
try {
  let doc = await firebase.firestore();
  doc.collection("users").doc(phoneNumber).get();

  if (!doc.exists) {
    alert("No user data found!");
  } else {
    let dataObj = doc.data();
    alert(doc.name);
  }
} catch (err) {
  alert(err);
}
}

for now, I am just using the user's phone number as a unique id. While there is user in collection, for some reason, i got :

alert("No user data found!");

I’m grateful for your advice

Update

  const user = firebase
    .firestore()
    .collection("users")
    .doc(phoneNumber)
    .get()
    .then((documentSnapshot) => {
      console.log("User exists: ", documentSnapshot.exists);

      if (documentSnapshot.exists) {
        console.log("User data: ", documentSnapshot.data());
      }
    });
0 Answers
Related