javascript - 在 Web 上的 Firebase 中将电话号码与 Facebook 和 Gmail 帐户相关联

标签 javascript facebook firebase authentication firebase-authentication

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

通过文档我无法找到适合我的用例的解决方案。帮助将不胜感激。

最佳答案

这是一个简单的示例,说明如何使用不可见的 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);
  });

关于javascript - 在 Web 上的 Firebase 中将电话号码与 Facebook 和 Gmail 帐户相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46659141/

相关文章:

php - Facebook 对 Drupal 的评论(所有节点上的评论相同)

android - Firebase 到自定义 Java 对象

Firebase 函数停止工作且无法再次部署

javascript - 将变量分配给样式属性的值不起作用

php - 带有电子邮件提交的Javascript弹出框

facebook - Facebook 以外的服务是否使用 Open Graph?

android - 您需要使用 Facebook 设置登录才能访问 API

javascript - 在 fullcalendar.js 中使用 PHP 日期时,条目提前一个月

javascript/php 从 facebook 应用程序重定向到应用程序商店

Firebase child_added 创建重复项