学习后,可以在最新的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。
如何使用firebase中的验证电子邮件验证使用电子邮件和密码登录的用户?这项工作背后的逻辑如何以及它在代码中的外观如何?
解决方案/帮助:对于那些仍在寻找答案的人,我发现了这个Post StackOverFlow Post