admin管理员组文章数量:1410682
I am having issues with my email verification. My error is "user is null" so it doesnt send the verification email, but it does show a log in uid in the console and my console.firebase.google project shows the signed up email. What should I change so an email is sent and no access is given until user has verified their email? I've read the docs but cant figure it out. Thank you in advance.
//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");
}
I am having issues with my email verification. My error is "user is null" so it doesnt send the verification email, but it does show a log in uid in the console and my console.firebase.google. project shows the signed up email. What should I change so an email is sent and no access is given until user has verified their email? I've read the docs but cant figure it out. Thank you in advance.
//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");
}
Share
Improve this question
edited Jan 5, 2018 at 22:54
Frank van Puffelen
601k85 gold badges890 silver badges860 bronze badges
asked Jan 5, 2018 at 22:51
nboris55nboris55
311 silver badge2 bronze badges
1
- alright, thank you. Is there a way to make the user not show up in the google firebase console until they have clicked the verify link in their email? – nboris55 Commented Jan 9, 2018 at 23:34
2 Answers
Reset to default 3For the Firebase version 9
, I am currently using -
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
sendEmailVerification(user)
.then(() => {
// Email verification sent!
let msg = 'An email verification link has been sent to ' + user.email;
document.querySelector('.success.email_msg').innerHTML=msg;
});
})
.catch((error) => {
document.querySelector('.error.reg_error').innerHTML = error.message;
});
You are not waiting for the promise to resolve. Update to the following snippet:
const promise = auth.createUserWithEmailAndPassword(email, pass);
promise.then(user => {
user.sendEmailVerification();
}).catch(error => console.log);
本文标签: javascriptfirebase email verification webStack Overflow
版权声明:本文标题:javascript - firebase email verification web - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744945321a2633740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论