i want to check if the person logged in with Google account, has registered before or not to save to Firestore. Is there any way to check?
const ggProvider = new GoogleAuthProvider();
const handleGgLogin = async () => {
const { user } = await signInWithPopup(auth, ggProvider);
const collectionRef = collection(db, "Account");
const payload = {
displayName: user.displayName,
email: user.email,
photoUrl: user.photoURL,
uid: user.uid,
};
await addDoc(collectionRef, payload);
};
CodePudding user response:
You're looking for the UserInfo.providerId
field of the User
object.
Something like this:
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/firebase.User
const uid = user.uid;
// Show the provider(s) that the user is signed in with
user.providerData.forEach((userInfo) => { //