I have a component that calls "getUserDocInfo()" which is in its own service. How would I go about calling that function and then using the returned data for further code?
My Component
getToken(){
this.userService.getUserDocInfo();
// once this is called I would like to use some of the values in the returned data
}
My Service
getUserDocInfo() {
this.getUserInfo().then(() => {
this.userDoc = this.afs.doc(`users/${this.userID}`);
this.user = this.userDoc.snapshotChanges();
this.user.subscribe(value => {
const data = value.payload.data();
});
})
}
async getUserInfo() {
const user = await this.authService.isLoggedIn()
if (user) {
this.userID = user.uid;
} else {
// do something else
}
}
Any help on best practises here would be greatly appreciated.