【问题标题】:Link Phone Number with Facebook and Gmail account in Firebase on Web在 Firebase 网页版中将电话号码与 Facebook 和 Gmail 帐户相关联
【发布时间】:2018-03-21 09:53:47
【问题描述】:

我正在使用 Firebase 服务在 React 中创建一个 Web 应用程序。我在登录屏幕上有 Google 和 Facebook 登录,登录后用户可以选择链接他们的手机。我为此使用 Firebase Phone Auth。用户已经签名,然后他们使用手机进行身份验证。我想将电话验证用户对象与 facebook/google 帐户链接。

浏览文档后,我找不到适合我用例的解决方案。帮助将不胜感激。

【问题讨论】:

    标签: javascript facebook firebase login firebase-authentication


    【解决方案1】:

    下面是一个简化示例,如何使用不可见的 reCAPTCHA 将电话号码链接到 Google/Facebook 用户。

    // Sign in the Google user first.
    firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
      .then(function(result) {
        // Google user signed in. Check if phone number added.
        if (!result.user.phoneNumber) {
          // Ask user for phone number.
          var phoneNumber = window.prompt('Provide your phone number');
          // You also need to provide a button element signInButtonElement
          // which the user would click to complete sign-in.
          // Get recaptcha token. Let's use invisible recaptcha and hook to the button.
          var appVerifier = new firebase.auth.RecaptchaVerifier(
              signInButtonElement, {size: 'invisible'});
          // This will wait for the button to be clicked the reCAPTCHA resolved.
          return result.user.linkWithPhoneNumber(phoneNumber, appVerifier)
            .then(function(confirmationResult) {
              // Ask user to provide the SMS code.
              var code = window.prompt('Provide your SMS code');
              // Complete sign-in.
              return confirmationResult.confirm(code);
            })
        }
      })
      .catch(function(error) {
        // console.log(error);
      });
    

    【讨论】:

    • 您能否提供您看到linkWithPhoneNumber(phoneNumber, appVerifier) 的链接/参考。 Firebase 文档的 Web 部分中没有此文档
    • 好的,参考文档吧:firebase.google.com/docs/reference/js/…
    • 非常感谢,这真的很有帮助
    猜你喜欢
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 2019-11-17
    • 2021-03-01
    相关资源
    最近更新 更多