Typescript Firebase additionalUserInfo.isNewUser始终返回false
我将ionic 4与firebase/angularfire2一起使用,并使用Typescript Firebase additionalUserInfo.isNewUser始终返回false,typescript,firebase,ionic-framework,firebase-authentication,angularfire2,Typescript,Firebase,Ionic Framework,Firebase Authentication,Angularfire2,我将ionic 4与firebase/angularfire2一起使用,并使用SignInWithMeailandPassword()方法进行身份验证,因此我需要在注册后检查该用户的首次登录,因此我发现firebase使用isNewUser提供了该选项 因此,当使用createUserWithEmailAndPassword()创建帐户时,isNewUser与true的值应相等或正常!但是当使用登录时,无论第一次登录与否,都会返回false 这是登录方法的代码: async login(for
SignInWithMeailandPassword()
方法进行身份验证,因此我需要在注册后检查该用户的首次登录,因此我发现firebase使用isNewUser提供了该选项
因此,当使用createUserWithEmailAndPassword()
创建帐户时,isNewUser与true
的值应相等或正常!但是当使用登录时,无论第一次登录与否,都会返回false
这是登录方法的代码:
async login(form: NgForm) {
// checking if login is valid
if (form.invalid)
return this.statusMessage.message('Validation error!');
console.log(this.user);
try {
const results = await this._afAuth.auth.signInWithEmailAndPassword(this.user.email, this.user.password).then(
user => console.log(user.additionalUserInfo.isNewUser)
);
// console.log(results);
} catch (error) {
switch (error.code) {
case "auth/user-not-found":
this.statusMessage.message("Your email address is wrong! please try again");
break;
case "auth/invalid-email":
this.statusMessage.message("You have enterd invalid email address");
break;
case "auth/wrong-password":
this.statusMessage.message('Password you have enterd is wrong');
break;
default:
console.dir(error);
this.statusMessage.message('Something wen wrong! please try again later');
break;
}
}
注册代码:
async register(form: NgForm) {
// checking for form validation
if (form.invalid) return this.statusMessage.message('Validation error!');
console.log(this.user);
try {
await this.afAuth.auth.createUserWithEmailAndPassword(this.user.email, this.user.password).then(
user => console.log(user)
);
} catch (error) {
this.statusMessage.message('Somthing went wrong!, please try again later.');
}
}
}
这是错误的,因为只有在他们第一次登录时才是正确的。当您调用createUserWithEmailAndPassword()
时,客户端将作为该用户登录。未来的标志不再考虑用户新的。
从:
成功创建用户帐户后,此用户也将登录到您的应用程序
正常登录时,isNewUser
唯一正确的情况是您在Firebase控制台或使用Firebase Admin SDK创建帐户。更多代码please@ShashankVivek你还需要什么?我已经用我使用的注册方法更新了问题!无论第一次登录与否,user.additionalUserInfo.isNewUser
的响应总是返回false,这是我的问题!就我所见,firebaser在这里,所以不可能在那里得到错误的值。你能在JSBin这样的网站上设置一个快速、最小的复制(最好只有JavaScript SDK,没有其他框架),这样我就可以与团队共享吗?@FrankvanPuffelen根据我所了解的createUserWithEmailAndPassword()
方法,在我调用它之后,它也会被用户登录!所以未来的签约不会再考虑用户的新情况了。我觉得很奇怪!对于使用isNewUser,我必须让用户在注册后重定向到他的个人资料!无需再次手动登录!!那么如何避免这种情况呢!我需要让用户注册,然后重定向到登录页面时,他登录重定向到个人资料页面,如果这是第一次登录到其他主页@heshamshawky只是在他们创建帐户时重定向他们,他们已经登录,没有必要在他们刚注册后让他们登录。回答得好Michael!我完全没有注意到问题出现在随后的登录中@heshamshawky:典型的处理方法是在用户登录后检测您是否拥有完整的用户配置文件。如果您没有完整的个人资料,您可以将其重定向到“完成您的个人资料”页面,否则将重定向到您的主要活动。