javascript - Check for isNewUser with Firebase email link auth using modular JS SDK - Stack Overflow

The official snippet here says: You can access the new user via result.user Additional user info pr

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" }); 
}

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" }); 
}
Share Improve this question edited Aug 15, 2021 at 12:15 Dharmaraj 51k8 gold badges67 silver badges98 bronze badges asked Aug 15, 2021 at 11:17 eozzyeozzy 68.9k109 gold badges285 silver badges447 bronze badges 3
  • Can you share your code where additionalUserInfo undefined? – Dharmaraj Commented Aug 15, 2021 at 11:20
  • @Dharmaraj Sure, done. – eozzy Commented Aug 15, 2021 at 11:32
  • Tried both, its the additionalUserInfo thats undefined – eozzy Commented Aug 15, 2021 at 11:33
Add a ment  | 

1 Answer 1

Reset to default 11

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                ^^^^^^

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744309357a4567874.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信