Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for isNewUser with Firebase email link auth using modular JS SDK

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" }); 
}
like image 783
eozzy Avatar asked Sep 17 '25 02:09

eozzy


1 Answers

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                ^^^^^^
like image 122
Dharmaraj Avatar answered Sep 18 '25 16:09

Dharmaraj