i want to create a document that has every user that signed in. So i'm creating the document as:
const submitUser = async (
name: string | undefined | null,
userId: string | undefined,
photo: string | undefined | null
) => {
const snapshot: DocumentData = await getDoc(doc(db, "allUsers", "list"));
const currentUsers: { name: string; uid: string; photo: string }[] =
snapshot.data().users;
if (currentUsers.map((item) => item.uid == auth.currentUser?.uid)) return;
else {
await setDoc(doc(db, "allUsers", "list"), {
users: [...currentUsers, { name, uid: userId, avatar: photo }],
});
console.log("success");
}
};
But if the user exists in the list, then it will just return. I'm calling the function as:
const googleSignIn = () => {
signInWithPopup(auth, provider).then((res) => {
setIsAuth(true);
auth.currentUser &&
submitUser(
auth.currentUser.displayName,
auth.currentUser.uid,
auth.currentUser.photoURL
);
});
};
But it's not adding new users to the list. What am i doing wrong?