繁体   English   中英

使用模块化 JS SDK 使用 Firebase email 链接验证检查 isNewUser

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

这里的官方片段说:

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

甚至API 参考也说:

Object,其中包含作为成功登录、链接或重新身份验证操作的结果的附加用户信息。

但是我得到additionalUserInfo is undefined 我需要检测 email 链接登录是否是新用户。

我的代码:

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

您需要在新模块 SDK 中单独使用getAdditionalUserInfo方法,如Github 问题中所述。

import {signInWithEmailLink, getAdditionalUserInfo} from "firebase/auth"

const result = await signInWithEmailLink(auth, email.value, window.location.href);
const {isNewUser} = getAdditionalUserInfo(result)
// Pass the UserCredential                ^^^^^^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM