2
votes

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.com 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");
    }
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

1 Answers

1
votes

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);