angular - 我如何检查 Angularfire 用户是否存在并具有身份验证标识符

标签 angular firebase firebase-authentication

我已经寻找了许多解决方案,但大多数都与检查身份验证用户是否登录或使用文档引用通读并检查用户电子邮件有关。

我想要实现的是通过运行用户输入并检查身份验证标识符电子邮件地址中的电子邮件是否已存在。 据我所知,身份验证实际上发出了类似 auth/email-already-in-use 的错误 这就是我现在所拥有的,但是当我尝试输入的每封电子邮件时,它总是会返回“用户已在使用中”

 checkAccountEmailExistInFirebase(email) {
    firebase.auth().fetchSignInMethodsForEmail(email).then(user => { 
     console.log("User already in use");
    }).catch(err => { 
      if (err.code === 'auth/user-not-found') {
        this.regEmail = email;
      }
    })

最佳答案

fetchSignInMethodsForEmail(email) 使用结果列表进行解析(调用 then())。仅当出现错误时(例如当您指定无效的电子邮件地址时),它才会拒绝(调用 catch)。

因此,您必须检查传递到 then() 的登录方法数组是否为空:

firebase.auth().fetchSignInMethodsForEmail(email)
  .then(function(signInMethods) {
    if (signInMethods.length > 0) {
      ...
    }
  })

另请参阅example in the Firebase documentation .

关于angular - 我如何检查 Angularfire 用户是否存在并具有身份验证标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58405210/

相关文章:

reactjs - 每次有人使用 firebase 和 Reactjs 访问页面时计算浏览次数

android - 当我在应用程序中添加Firebase Realtime数据库时,它开始崩溃

firebase-authentication - 即使我已通过匿名身份验证,也无法对 Firebase 存储进行身份验证

javascript - 在 Apache 服务器上部署 Angular 2 应用程序

css - NG-ZORRO nz卡体内对准

angular - 从docker ui容器调用到api容器

ios - 使用 Firebase 的 Xcode 编译错误

android - 禁用 Firebase 云消息传递的分析服务

angular - 在 Angular 2 中过滤数组之前,如何设置 i=index of array?

android - 如何在 Firebase 创建用户时获取用户 ID