Firebase additionalUserInfo.isNewUser 总是 return 错误
Firebase additionalUserInfo.isNewUser is always return false
我将 ionic 4 与 firebase/angularfire2 一起使用,并使用 signinwithemeailandpassword()
方法进行身份验证,因此我需要检查用户在注册后首次登录的时间,所以我发现 firebase 使用 [=15= 提供了该选项]
因此,当使用 createUserWithEmailAndPassword()
创建帐户时,isNewUser 是 equal
到 true
,这是正常的!但是当使用 signinwithemeailandpassword()
登录时总是 returns 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()
时,客户端以该用户身份登录。以后的登录将不再考虑新用户。
On successful creation of the user account, this user will also be signed in to your application.
只有当您在 Firebase 控制台或使用 Firebase Admin SDK 创建帐户时,isNewUser
对于正常登录才成立。
我将 ionic 4 与 firebase/angularfire2 一起使用,并使用 signinwithemeailandpassword()
方法进行身份验证,因此我需要检查用户在注册后首次登录的时间,所以我发现 firebase 使用 [=15= 提供了该选项]
因此,当使用 createUserWithEmailAndPassword()
创建帐户时,isNewUser 是 equal
到 true
,这是正常的!但是当使用 signinwithemeailandpassword()
登录时总是 returns 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()
时,客户端以该用户身份登录。以后的登录将不再考虑新用户。
On successful creation of the user account, this user will also be signed in to your application.
只有当您在 Firebase 控制台或使用 Firebase Admin SDK 创建帐户时,isNewUser
对于正常登录才成立。