What is the difference between authState and user in AngularFire Authentication?

Viewed 151

I am working on integrating Authentication into my Angular+Firebase app using Angular Fire. While doing so, I have come across numerous examples that use authState to get a hold of the user's metadata such as their displayName and uid.

Note: fireAuth is of type AngularFireAuth.

Here is a sample:

this.fireAuth.authState.pipe(
      take(1),
      map(user => {
        if (user) {
          return {uid: user.uid, email:user.email, displayName:user.displayName}
        } else {
          return null;
        }
      })
    );

But I noticed, in the Documentation for AngularFire, they simply used user instead of authState. So I refactored the code a bit and ended up getting similar results:

this.fireAuth.user
    .subscribe(result => {
      if(result) {
        console.log(result.displayName);
      } else {
        console.log("USER IS NOT LOGGED IN");
      }
    });

Here, result.displayName is producing the same result when I use fireAuth.user as well as when I use fireAuth.authState. So what is the difference between the two?

0 Answers
Related