I have this method inside a authProvider
provider class:
getUser() {
return this.afAuth.authState.subscribe(user => {
return user;
});
}
I would like to subscribe to it in a different class, something like:
this.authProvider.getUser().subscribe(user => console.log(user));
any ideas how to return an Observable
inside the getUser()
method?
Your
authState
is already Observable. Just return yourauthState
and subscribe within another function. In the function for any other work you can use RxJS#map function.