【问题标题】:how to know if phone number already linked with the password account in firebase web before OTP sent to user在将 OTP 发送给用户之前,如何知道电话号码是否已与 Firebase Web 中的密码帐户相关联
【发布时间】:2019-11-17 17:34:55
【问题描述】:

我正在创建一个带有 firebase 身份验证的 ionic 应用程序。我提供了“facebook 登录”和“密码验证”功能。当用户尝试通过上述两个功能登录时,我希望他们将他们的电话号码与他们的 Facebook 或密码验证帐户相关联。我已经实现了将电话号码与他们的帐户关联的功能。

我的要求是:我想检查他们尝试链接的电话号码是否已被 firebase 用户中的其他用户链接。如果不是,我允许他们链接,否则我不会。另外,我希望在将 OTP 发送给用户之前获得此结果。

this.confirmationResult = this.auth.userCredential.user。 linkWithPhoneNumber(this.phoneNumber, this.appVerifier);

如果电话号码已与其他帐户关联,我希望上述代码应该返回错误。 但是,它允许将 OTP 发送到用户的电话号码,然后提示我提供发送到电话号码的代码。 此外,我可以在验证 OTP 后收到错误代码 “身份验证/凭据已在使用中”。在将代码发送到用户的电话号码之前,我想要这个。请帮我实现这个场景。

【问题讨论】:

    标签: firebase web firebase-authentication


    【解决方案1】:

    您可以使用 Firebase Admin SDK 来lookup 是否已经存在具有电话号码的用户。

    这是一个使用 Node.js 的示例

    admin.auth().getUserByPhoneNumber(phoneNumber)
      .then(function(userRecord) {
        // A user with the phone number already exists.
        // You can also get other information related to the user from the
        // userRecord.
      })
      .catch(function(error) {
        console.log('Error fetching user data:', error);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2018-03-21
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      相关资源
      最近更新 更多