Firebase email verification at SignUp

♀尐吖头ヾ 提交于 2019-12-31 04:47:23

问题


How should I go about verifying an email address prior to the user signing up with Firebase? I know that an email address is verified with .sendEmailVerification, however this only works on the current user. Hence a user must be already created before sending a verification email. This would not be of much help since you obviously have to verify an email before adding it to your database. Therefore, what is a good workaround?


回答1:


You can't verify the email prior to sign up with Firebase Auth. Email verification is not always required. This is why Firebase Auth provides it as a method on the user. Some applications do not require email verification on sign-up, others may make it optional, others may offer limited access to unverified users, etc.

If you want to require users to be verified before accessing your app content, you can either: enforce that via Firebase rules, eg: ".read": "auth.token.email_verified === true"

Or, if you are using your own backend, use the Firebase Admin SDK, https://firebase.google.com/docs/auth/admin/verify-id-tokens:

admin.auth().verifyIdToken(idToken).then(decodedToken => {
  if (decodedToken.email_verified) {
    // Email verified. Grant access.
  } else {
    // Email not verified. Ask user to verify email.
  }
});


来源:https://stackoverflow.com/questions/48028927/firebase-email-verification-at-signup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!