I need guidance on how to effectively utilize the "getUserDocInfo()" function from a separate service within my component. How can I call this function and then leverage the data it returns for further operations?
Component Example
getToken(){
this.userService.getUserDocInfo();
// Once the data is returned, I want to extract and use certain values
}
Service Implementation
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 {
// Handle alternative scenario
}
}
If you have any tips or best practices to share regarding this scenario, please feel free to offer your suggestions.