Firebase confirmation email not being sent

After creating a user a User object is returned, where you can check if the user's email has been verified or not.

When a user has not been verified you can trigger the sendEmailVerification method on the user object itself.

firebase.auth()
    .createUserWithEmailAndPassword(email, password)
    .then(function(user){
      if(user && user.emailVerified === false){
        user.sendEmailVerification().then(function(){
          console.log("email verification sent to user");
        });
      }
    }).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;

      console.log(errorCode, errorMessage);
    });

You can also check by listening to the AuthState, the problem with the following method is, that with each new session (by refreshing the page), a new email is sent.

firebase.auth().onAuthStateChanged(function(user) {
  user.sendEmailVerification(); 
});

I noticed that the new Firebase email authentication docs is not properly documented.

firebase.auth().onAuthStateChanged(function(user) {
  user.sendEmailVerification(); 
});

Do note that:

  1. You can only send email verification to users object whom you created using Email&Password method createUserWithEmailAndPassword
  2. Only after you signed users into authenticated state, Firebase will return a promise of the auth object.
  3. The old onAuth method has been changed to onAuthStateChanged.

To check if email is verified:

firebase.auth().onAuthStateChanged(function(user) { 
  if (user.emailVerified) {
    console.log('Email is verified');
  }
  else {
    console.log('Email is not verified');
  }
});