firebaseauthenticationfirebase-authenticationemail-verification

Firebase confirmation email not being sent


I've set up Firebase email/password authentication successfully, but for security reasons I want the user to confirm her/his email. It says on Firebases website:

When a user signs up using an email address and password, a confirmation email is sent to verify their email address.

But when I sign up, I doesn't receive a confirmation email.

I've looked and can only find a code for sending the password reset email, but not a code for sending the email confirmation.

I've looked here:

https://firebase.google.com/docs/auth/ios/manage-users#send_a_password_reset_email

anyone got a clue about how I can do it?


Solution

  • 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');
      }
    });