我的电子邮件验证存在问题。我的错误是“用户为空”,因此它不会发送验证电子邮件,但它会在控制台中显示uid中的日志,而我的console.firebase.google.com项目会显示已注册的电子邮件。我应该更改哪些内容,以便在用户验证其电子邮件之前发送电子邮件并且不会进行访问?我已经阅读了文档,但无法弄明白。提前谢谢。
//add create user event
btnSignUp.addEventListener('click', e => {
//get email and Password
const email = txtEmail.value;
const pass = txtPassword.value;
const auth = firebase.auth();
const promise = auth.createUserWithEmailAndPassword(email, pass);
var user = firebase.auth().currentUser;
user.sendEmailVerification();
promise.catch(e => console.log(e.message));
});
//Add a realtime listener
firebase.auth().onAuthStateChanged(function(user) {
if (user.emailVerified) {
console.log('Email is verified');
console.log(user);
} else {
window.location = "index.html";
firebase.auth().signOut();
alert("Email is not verified");
}
答案 0 :(得分:0)
你不是在等待解决的承诺。更新到以下代码段:
const promise = auth.createUserWithEmailAndPassword(email, pass);
promise.then(user => {
user.sendEmailVerification();
}).catch(error => console.log);