从Firebase ui auth电话号码身份验证系统保存用户确认的电话号码

时间:2018-08-14 22:47:38

标签: javascript firebase callback firebase-authentication firebaseui

/**
 * @return {!Object} The FirebaseUI config.
 */
function getUiConfig() {
  return {
    'callbacks': {
      // Called when the user has been successfully signed in.
    'signInSuccess': function(user, credential, redirectUrl) {
    // You can also access this via 
    //document.cookie = (firebase.auth().currentUser.phoneNumbe)
   //setCookie('phoneNumber', firebase.auth().currentUser.phoneNumber);
  


    handleSignedInUser(user);
    // Do not redirect.
    //'signInSuccessUrl': "http://localhost:8080/CurrentLocation.html",
    return true;
  }
    },
    // Opens IDP Providers sign-in flow in a popup.
    'signInSuccessUrl':  "http://localhost:1357/Carrier/homepage_latest.html",
    'signInFlow': 'popup',
    'signInOptions': [
      // The Provider you need for your app. We need the Phone Auth
      //firebase.auth.TwitterAuthProvider.PROVIDER_ID,
      {
        provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
        recaptchaParameters: {
          type: 'image', // another option is 'audio'
          size: 'invisible', // other options are 'normal' or 'compact'
          badge: 'bottomleft' // 'bottomright' or 'inline' applies to invisible.
        }
      }
    ],
    // Terms of service url.
    'tosUrl': 'https://www.google.com'
  };
}

我正在尝试找到一种方法,可以在用户使用发短信到其电话号码的代码进行确认后,保存该电话号码。我在github上发布了这个问题,一个用户提到我可以使用signInSuccesWithAuthResult callback. In the ui config, you can provide a signInSuccesWithAuthResult and save the phone number to cookie in the callback. You can access the phone number by doing authResult.user.phoneNumber.到这个github论坛的链接是https://github.com/firebase/firebaseui-web/issues/383#issuecomment-387167882,我对如何执行此操作感到困惑。我需要保存确认的电话号码并将其显示在html5文件中。特别是,我需要将其显示为Google Maps API图钉的标记标签。

var data = snapshot.val();
  var markerLabel = 

  var marker = new google.maps.Marker({
    position: {
      lat: data.User.l[0],
      lng: data.User.l[1]
    },
    map: map,
    label: markerLabel
  });
 如果有人可以帮助我,我将不胜感激

1 个答案:

答案 0 :(得分:0)

从您想显示电话号码的html / js文件中,您仍然应该能够通过firebase.auth()访问相同的Firebase Auth实例。从那里开始,只要用户登录,就可以通过firebase.auth().currentUser.phoneNumber获得电话号码。