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

前端 未结 4 1472
囚心锁ツ
囚心锁ツ 2021-02-05 18:55

I have an ionic2 app and am using Firebase and angularFire2. I\'d like to get the current authentication state and current auth object/user from firebase using angularFire2.

4条回答
  •  Happy的楠姐
    2021-02-05 19:16

    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');
        }
      });
      

提交回复
热议问题