繁体   English   中英

我可以在Firebase身份验证中验证电子邮件的域区域吗?

[英]Can I validate email's domain zone in Firebase Authentication?

我可以在Firebase身份验证中验证电子邮件域区域吗?

例如,我只想为来自yahoo和gmail的电子邮件 @ yahoo.com, @ gmail.com电子邮件)进行成功注册。

ps当然我可以在客户端验证它,但这还不够

不幸的是,您无法在注册之前验证电子邮件的域(不包括客户端)。

您可以执行一些选择:

  • 选项1:如果用户的域不是您的某些特定域,则防止访问数据库和存储:

例如:

"rules": {
    ".read": "auth.token.email.endsWith('@gmail.com')",
    ".write": "auth.token.email.endsWith('@gmail.com')"
  }
}

或像这样:

"rules": {
    ".read": "auth.token.email_verified == true && auth.token.email.matches(/.*@gmail.com$/)",
    ".write": "auth.token.email_verified == true && auth.token.email.matches(/.*@gmail.com$/)"
  }
}

积分: https : //stackoverflow.com/a/38019847/2765346

  • 选项2:添加Firebase身份验证触发器并侦听新用户。 然后,您可以验证新注册的用户并使用无效的域禁用它们:

例如:

exports.validateUser = functions.auth.user().onCreate((user) => {
   if (!user.email.matches(/.*@gmail.com$/)) {
       admin.auth().updateUser(data, {
           disabled: true
       });
   }
});

积分: https : //firebase.google.com/docs/functions/auth-events

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM