javascript Firebase V9认证时如何检查用户是否为新用户?[duplicate]

t3irkdon  于 2022-12-28  发布在  Java
关注(0)|答案(1)|浏览(120)
    • 此问题在此处已有答案**:

Check for isNewUser with Firebase email link auth using modular JS SDK(1个答案)
15小时前关门了。
在v8中,我是这样做的:

const userCredential = await firebase.auth().signInAnonymously();
console.log('is new user: ', userCredential.additionalUserInfo.isNewUser());

然而,在V9中:

const userCredential = await SignInWithPopup(auth, googleProvider);
try {
  userCredential.additionalUserInfo.isNewUser()
}
catch (e) {
  console.log(e);
  /* [!] TypeError: Cannot read properties of undefined (reading 'isNewUser') */
}

additionalUserInfo在signin函数返回的UserCredential对象上不存在,在V9中应该怎么做?

tjvv9vkg

tjvv9vkg1#

如果登录成功,则返回的UserCredentials对象将包含当前用户的user属性。通过比较其metadata属性的creationTimelastSignInTime,可以确定这是否是新用户。如果它们之间的间隔不超过几毫秒,则表明刚刚创建了该用户。

相关问题