首页 > 解决方案 > 使用包含已验证电话号码值的 cookie 标记 Google 地图标记

问题描述

这是我创建 cookie 以保存已验证电话号码的地方

    'signInSuccess': function(user, credential, redirectUrl) {
    // You can also access this via firebase.auth().currentUser.phoneNumber
    document.cookie =  (firebase.auth().currentUser.phoneNumber);
    handleSignedInUser(user);
    // Do not redirect.
    //'signInSuccessUrl': "http://localhost:8080/CurrentLocation.html",
    return true;
  }

这是我使用 cookie 值来标记 Google 地图标记的地方

var markerLabel = document.cookie;
  var marker = new google.maps.Marker({
    position: {
      lat: data.User.l[0],
      lng: data.User.l[1]
    },
    map: map,
    label: markerLabel
  });

标记标签说

电话号码=未定义;+1##########

它显示用户的验证号码,但也显示未定义。我只想显示电话号码。

在此处输入图像描述

标签: javascriptfirebasefirebase-authenticationgoogle-maps-markersfirebaseui

解决方案


您没有正确设置 cookie。查找设置/获取 cookie 的正确方法:https ://www.w3schools.com/js/js_cookies.asp

另外,为什么需要使用cookie来保存电话号码?Firebase Auth 已经保留了用户。在监听器触发firebase.auth().currentUser.phoneNumber后,您可以通过调用获取电话号码。onAuthStateChanged


推荐阅读