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

标签 javascript firebase firebase-authentication angularfire2

<分区>

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

例如,我想给来自yahoo和gmail的邮件(@yahoo.com, @gmail.com emails)

注册成功

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

最佳答案

很遗憾,您无法在注册前验证电子邮件的域(客户端除外)。

有一些选项摆在你面前,你可以做:

  • 选项 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

关于javascript - 我可以在 Firebase 身份验证中验证电子邮件的域区域吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54940057/

相关文章:

javascript - Firebase 更新电子邮件地址 HTML 表单

javascript - 如果为空或使用ajax添加带值的逗号,如何将值附加到输入?

javascript - Ajax 调用时出错 -> 发送两个文件而不是一个

ios - Firebase Flutter ios 应用程序卡在 "Run your app to verify installation"步骤

java - 如何将图像从存储链接到实时数据库(Firebase)

android - Firebase - Android - fetchProvidersForEmail - 为什么所有调用都是异步的?

iOS FIRAuth : Is there any way to get user email from user uid?

javascript - 如何在 AJAX 返回的 HTML 中调用 jQuery 函数

javascript - Loopback API 和 Promise

amazon-web-services - 使用 Firebase 和 s3 存储图像