I am trying to get the user model from firestore. I subscribe to it and can log the user model within the subscription, but when I try and set the outcome to a variable and use it outside of the subscription it returns null.
this.user$ = this.afAuth.authState.pipe(
switchMap(
(auth) =>
(auth)
? this.afs.doc(`users/${auth.uid}`).valueChanges()
: of(null)
));
this.user$.subscribe((user) => this.user = user);
console.log(this.user)
So as mentioned, console logging user within the subscription does return the current object, but the outer console.log of this.user returns 'undefined'
EDIT
I am trying to pass the data from this.user into the following get function:
get userDb() {
return this.user;
}
which can then be used throughout the application.
console.log
on the last line ran before the data is available. – smtaha512