With latest version of Firebase Javascript SDK (10.1.0) I am using signInWithPopup
to authenticate users through Providers and then saving their credentials inside the DB:
userCredentials = await signInWithPopup(auth, new GoogleAuthProvider());
await setDoc(
doc(db, "users", userCredentials.user.uid),
{
uid: userCredentials.user.uid,
email: userCredentials.user.email,
...,
},
{ merge: true },
);
How can I know if the recently set document was created (user was authenticated for the first time, i.e. signed up to the service) or updated (user was already registered)?
PS: I would like to avoid querying the DB to check for existing email, as I would need to change the access rules and make all users data available to anyone.