- 此问题在此处已有答案**:
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中应该怎么做?
1条答案
按热度按时间tjvv9vkg1#
如果登录成功,则返回的
UserCredentials
对象将包含当前用户的user
属性。通过比较其metadata
属性的creationTime
和lastSignInTime
,可以确定这是否是新用户。如果它们之间的间隔不超过几毫秒,则表明刚刚创建了该用户。