How to get currently logged in auth state/user from angularfire2

  1. Import: import { AngularFireAuth } from 'angularfire2/auth';
  2. Inject: constructor(public afAuth: AngularFireAuth) { }
  3. Check:

    this.afAuth.authState.subscribe(res => {
      if (res && res.uid) {
        console.log('user is logged in');
      } else {
        console.log('user not logged in');
      }
    });
    

now in order to get the user info, you have to subscribe for getting the auth information. Ex

  constructor(public af: AngularFire) {
    this.af.auth.subscribe(auth => console.log(auth));// user info is inside auth object
  }

auth object will be null if auth state does not exist