How do I grab the logged in user?
I am doing this: console.log('Logging in...'); this.afAuth.auth.signInWithEmailAndPassword(this.email, this.password);
But the docs are not clear on how to get the user in code. They show a way in the template but I need to store the current user.
AngularFireAuth.authState is an Observable, so you can subscribe on it, and then get user instance :
private user: firebase.User;
constructor(public afAuth: AngularFireAuth) {
afAuth.authState.subscribe(user => {
this.user = user;
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With