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