Kho*_*Phi 7 javascript firebase firebase-authentication
学习后,可以在最新的Firebase中发送电子邮件验证,尽管文档丢失了,但我想自己进行测试。
使用以下代码段:
Auth.$onAuthStateChanged(function(firebaseUser) {
if (firebaseUser) {
console.log(firebaseUser);
if (firebaseUser.emailVerified) {
// console.log(firebaseUser.emailVerified);
toastr.success('Email verified');
} else {
toastr.info('Do verify email');
}
}
})
Run Code Online (Sandbox Code Playgroud)
在console.log(firebaseUser.emailVerified)返回false,总是,虽然发送的验证已启动,收到的邮件,并点击。
使用电子邮件登录后,我立即检查是否已验证用户,如果未通过验证,则应发送电子邮件:
Auth.$signInWithEmailAndPassword(email, password)
.then(function(firebaseUser) {
if (!firebaseUser.emailVerified) {
firebaseUser.sendEmailVerification();
console.log('Email verification sent');
}
$state.go('home');
})
Run Code Online (Sandbox Code Playgroud)
在my https://console.firebase.google.com/project/my-app-name/authentication/emails下,默认情况下所有内容均为默认值,其中的验证链接为:
Follow this link to verify your email address.
https://my-app-name.firebaseapp.com/__/auth/handler?mode=<action>&oobCode=<code>
我用来注册的电子邮件会收到验证电子邮件,但是,单击链接并不能将更改user.emailVerified为true。
我只是采取了相同的步骤:
auth.currentUser.emailVerified
Run Code Online (Sandbox Code Playgroud)
错误的
auth.currentUser.sendEmailVerification()
Run Code Online (Sandbox Code Playgroud)
进而
auth.currentUser.emailVerified
Run Code Online (Sandbox Code Playgroud)
真的
注意第 3 步和第 4 步:emailVerified在我的应用程序中显示的新值之前,我需要再次登录。
这个答案似乎也很相关,但我在写完上述内容后才发现它:Firebase 确认电子邮件未发送