注册时的 Firebase 电子邮件验证 [英] Firebase email verification at SignUp
问题描述
在用户注册 Firebase 之前,我应该如何验证电子邮件地址?我知道使用 .sendEmailVerification
验证电子邮件地址,但这仅适用于当前用户.因此,在发送验证电子邮件之前必须已经创建了用户.这不会有太大帮助,因为您显然必须在将电子邮件添加到数据库之前对其进行验证.因此,什么是好的解决方法?
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?
推荐答案
您无法在注册 Firebase Auth 之前验证电子邮件.电子邮件验证并不总是需要的.这就是 Firebase Auth 将其作为用户方法提供的原因.某些应用程序在注册时不需要电子邮件验证,其他应用程序可能将其设为可选,其他应用程序可能会为未经验证的用户提供有限的访问权限等.
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.
如果您想要求用户在访问您的应用内容之前进行验证,您可以:通过 Firebase 规则强制执行,例如:".read": "auth.token.email_verified === true"
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"
或者,如果您使用自己的后端,请使用 Firebase Admin SDK,https://firebase.google.com/docs/auth/admin/验证 ID 令牌:
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.
}
});
这篇关于注册时的 Firebase 电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!