The official snippet here says:
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
Even the API reference says :
Object that contains additional user information as a result of a successful sign-in, link, or re-authentication operation.
However I get additionalUserInfo is undefined
. I need to detect if the email link login is a new user or not.
My code:
await setPersistence(auth, browserLocalPersistence);
const result = await signInWithEmailLink(auth, email.value, window.location.href);
if (result && result.user) {
window.localStorage.removeItem('email');
window.localStorage.removeItem('its');
console.log(result.additionalUserInfo.isNewUser()); // undefined
return router.push({ path: "/dashboard" });
}
You need to use the getAdditionalUserInfo
method separately in the new modular SDK as mentioned in this Github issue.
import {signInWithEmailLink, getAdditionalUserInfo} from "firebase/auth"
const result = await signInWithEmailLink(auth, email.value, window.location.href);
const {isNewUser} = getAdditionalUserInfo(result)
// Pass the UserCredential ^^^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With