将电话号码与 Firebase 网页版中的 Facebook 和 Gmail 帐户关联

2023-11-26

我正在使用 Firebase 服务在 React 中创建一个 Web 应用程序。我在登录屏幕上登录了 Google 和 Facebook,登录后用户可以选择链接他们的手机。我使用 Firebase电话验证为了这。用户已经签名,然后他们使用手机进行身份验证。我想将电话身份验证用户对象与 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);
  });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将电话号码与 Firebase 网页版中的 Facebook 和 Gmail 帐户关联 的相关文章

随机推荐