Uncaught TypeError: Cannot read property 'uid' of null using website

╄→尐↘猪︶ㄣ 提交于 2019-12-04 10:25:44

Your error says Cannot read property 'uid' of null. which means you are loading myProfile() this function on page load, by that time user may be null. There will be a lag to fetch auth details from firebase. Try this way

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
    var db = firebase.firestore();
      var docRef = db.collection("deyaPayusers").doc(user.uid);
      docRef.get().then(function(doc) {
         if(doc && doc.exists) {
         const myData = doc.data();
         const ffname = myData.FirstName;
         const llname = myData.LastName;
         const phonen = myData.PhoneNumber;
         document.getElementById("fname").value = ffname;
         document.getElementById("lname").value = llname;
         document.getElementById("phone").value = phonen;

    }
    }).catch(function(error) {
    console.log("Got an error: ",error);
    });
  } else {
    // No user is signed in.
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!