I'm not able to query an user by its id in users collection (firebase/firestore v9)

216 views
Skip to first unread message

Ricardo Domene

unread,
Mar 25, 2022, 12:10:15 AM3/25/22
to Firebase Google Group
Good Afternoon everybody,
I need to do a query in firestore collection "users" and find for a specific user.email and get this user document as return

The context is that i'm doing an authentication flow and i must to know if the user returned successfully from firebase/auth it's already in my firestore database or not.

This is the function that i'm trying to get this return but i'm not getting success

async function getUserByEmail(email: string) {
const docRef = doc(db, "users", email);
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}

What i'm doing wrong? i think i'm using the wrong method...
I've tried to learn the documentation but i thought confuse

Please i ask for your help!

Reply all
Reply to author
Forward
0 new messages