在注册时进行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屋!