I want to get registered user details from firestore into html page. When user clicks my profile page it navigate to next html page with fields like first name and last name
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.
}
});