【问题标题】:save users confirmed phone number from firebase ui auth phone number authentication system从firebase ui auth电话号码认证系统保存用户确认的电话号码
【发布时间】:2023-04-07 17:57:01
【问题描述】:

/**
 * @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 pin 的标记标签。

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
  });
如果有人可以帮助我,我将不胜感激

【问题讨论】:

    标签: javascript firebase callback firebase-authentication firebaseui


    【解决方案1】:

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

    【讨论】:

    • 您能否编辑我的代码以反映您的评论
    猜你喜欢
    • 2018-10-17
    • 2017-11-06
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 2018-03-03
    相关资源
    最近更新 更多