验证后Angular Firebase电子邮件验证为假 [英] Angular firebase email verification false after verify
问题描述
我正在使用电子邮件和密码设置授权功能.一切正常,但是当我创建一个新用户时,该应用程序会发送一封包含验证链接的电子邮件.验证电子邮件地址后,我想登录,以便回到登录表单. emial_verified始终保持为"false",在我重新加载页面后,此属性为"true",但是当我从验证页面返回登录页面时却没有.有人可以帮我吗?
I'm setting up an authorisation function with e-mail and password. Everything works fine but when i create a new user, the application sends an e-mail with a verification link. After i verify the e-mail adres I want to login so i get back to the login form. the emial_verified keeps staying at 'false', after i hard reload the page this is 'true', but not when i come frome the verification page back to the login page. Can someone help me?
constructor(
public afs: AngularFirestore, // Inject Firestore service
public afAuth: AngularFireAuth, // Inject Firebase auth service
public router: Router,
public ngZone: NgZone // NgZone service to remove outside scope warning
) {
/* Saving user data in localstorage when
logged in and setting up null when logged out */
this.afAuth.authState.subscribe(user => {
if (user) {
this.userData = user;
localStorage.setItem('uid', this.userData.uid);
localStorage.setItem('user', JSON.stringify(this.userData));
JSON.parse(localStorage.getItem('user'));
} else {
localStorage.setItem('user', null);
JSON.parse(localStorage.getItem('user'));
}
})
}
// Sign up with email/password
SignUp(email, password) {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((result) => {
console.log(result);
/* Call the SendVerificaitonMail() function when new user sign
up and returns promise */
this.SendVerificationMail();
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
// Send email verfificaiton when new user sign up
SendVerificationMail() {
return this.afAuth.auth.currentUser.sendEmailVerification()
.then(() => {
this.router.navigate(['verify-email-address']);
})
}
推荐答案
这不是bug,而是预期的行为.
This is not a bug, but expected behavior.
电子邮件验证是带外进行的(例如:单击电子邮件客户端中而不是应用程序中的链接),因此应用程序不知道验证状态已更改.这意味着它无法自动刷新客户端中的ID令牌(客户端从中获取配置文件信息的位置).
Email verification happens out of band (as in: you click a link in your email client, not in the app), so the app is not aware of the verification status being changed. This means that it can't automatically refresh the ID token, which is where the client gets profile information comes from, in the client.
令牌会每小时刷新一次,因此最终会更新.如果要尽快获取更新的值,可以强制刷新令牌.
The token auto-refreshes every hour, so it will update eventually. If you want to get the updated value sooner, you can force the token to refresh.
另请参阅:
- Firebase电子邮件验证未更新状态
- 我在这里给出的答案: Firebase自定义声明如何设置?
- Firebase Firestore无法更新电子邮件验证状态
- Firebase电子邮件验证无法验证帐户
- user.emailVerified在单击后不会更改电子邮件验证链接Firebase
- Firebase email verification not updating status
- the answer I just gave here: Firebase custom claim how to set?
- Firebase firestore not updating email verification status
- Firebase email verification doesn't verify account
- user.emailVerified doesn't change after clicking email verification link firebase
这篇关于验证后Angular Firebase电子邮件验证为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!