Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing the current user in AngularFireAuth

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.

like image 250
Peter S Avatar asked Oct 14 '17 19:10

Peter S


Video Answer


1 Answers

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;
    });
  }
like image 110
igor Avatar answered Sep 27 '22 23:09

igor