未发送 Firebase 确认电子邮件

问题描述:

我已成功设置 Firebase 电子邮件/密码身份验证,但出于安全原因,我希望用户确认她/他的电子邮件.它在 Firebases 网站上说:

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.

我看过这里:

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

有人知道我该怎么做吗?

anyone got a clue about how I can do it?

我注意到新的 Firebase 电子邮件身份验证文档没有正确记录.

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

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

请注意:

  1. 您只能向您使用电子邮件和密码方法创建的用户对象发送电子邮件验证createUserWithEmailAndPassword
  2. 只有在您将用户签名为已验证状态后,Firebase 才会返回 auth 对象的承诺.
  3. 旧的 onAuth 方法已更改为 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');
  }
});