I am looking to extract information from a firestore database and link it to the vue data.
To retrieve data from firestore, I use the following method within the created lifecycle hook:
created(){
console.log(firebase.auth().currentUser);
const docRef = firebase.firestore().collection("users").doc("VezLOaumLCza8jih8Ylk");
docRef.get().then(
function(doc){
if(doc.exists){
console.log(`Document data: ${doc.data()}`);
this.user = doc.data();
} else {
console.log(`Doc data is undefined`);
}
}).catch(function(err){
console.log(`Oops: ${err.message}`);
});
}
The problem arises when this
does not point to the vue instance; in fact, it is undefined at the moment I try to assign the user variable. How can I connect the user data to the vue data? It seems like I am overlooking something, but I cannot identify what might be causing the issue.
The end goal is to create a form that allows users to edit their own data.
(the expected results are obtained when printing out the doc.data())