'How to get document after user has logged in using google auth in firebase?

I want to fetch user information stored in firestore after the user has logged in using google sign in. I am checking whether the user exists or not. If the user does not exist then I am creating a new document in firestore.

 const q = query(collection(db, "users"),where("uid", "==", user.uid));

 getDocs(q).then((doc) => {
      if (doc.docs.length === 0) {
        addDoc(collection(db, "users"), {
          uid: user.uid,
          name: user.displayName,
          authProvider: "google",
          email: user.email,
          lists: [],
        }).then((response) => {
          console.log(response);
        });
      }else{
        console.log(doc.docs);
      }

user is the user Object I am getting after google sign in.

The doc.docs is not giving the document data which I need, namely lists. How do fetch that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source