在网页版 Firebase 中将电话号码与 Facebook 和 Gmail 帐户关联 [英] Link Phone Number with Facebook and Gmail account in Firebase on Web

查看:25
本文介绍了在网页版 Firebase 中将电话号码与 Facebook 和 Gmail 帐户关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating a web app in React with firebase services. I have Google and Facebook login on the login screen and after login user gets an option to link their phone. I use Firebase Phone Auth for this. The user is already signed then they Auth using the phone. I want to Link Phone Auth user object with facebook/google account.

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

Going through the docs I was not able to find the solution that suits my use case. Help will be appreciated.

推荐答案

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

Here is a simplified example how to link a phone number to a Google/Facebook user using an invisible reCAPTCHA.

// 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);
  });

这篇关于在网页版 Firebase 中将电话号码与 Facebook 和 Gmail 帐户关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆