【问题标题】:How do i check if angularfire user exist with the authentication identifier如何使用身份验证标识符检查 angularfire 用户是否存在
【发布时间】:2019-10-16 03:11:04
【问题描述】:

我查看了许多解决方案,但其中大部分都与检查 auth 用户是否已登录或使用文档参考阅读并检查用户电子邮件有关。

我想要实现的是通过运行用户输入并在身份验证标识符电子邮件中检查电子邮件是否已经存在。 据我所知,auth 实际上会发出错误,例如 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;
      }
    })

【问题讨论】:

  • 当您使用 Firebase 身份验证中不存在的电子邮件时,您是否尝试检查您的 user 是否为 null?
  • 如果没有现有电子邮件,则用户返回[] 的数组,如果有用户则返回["password"]

标签: angular firebase firebase-authentication


【解决方案1】:

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

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

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

另请参阅example in the Firebase documentation。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-15
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    相关资源
    最近更新 更多