firebase.User issue

Can someone please help me solve the below Observable problem.

user : Observable<firebase.User| null >
constructor(private afAuth : AngularFireAuth) {
this.user = afAuth.authState

Error: Type ‘User | null’ is not assignable to type ‘Observable<User | null>’.
Type ‘null’ is not assignable to type ‘Observable<User | null>’.

The error says that afAuth.authState is null which does not match the expected type Observable<firebase.User | null> (which means either Observable<firebase.User> or Observable<null>). And that is true. null is not Observable<null> and it is definitely not Observable<firebase.User>.

Looking at the current angularfire docs it looks like AngularFireAuth is just a thin wrapper around firebase.auth.Auth that proxies calls and wraps them in Promises / Observables. Those documents also suggest that the correct way to use AngularFireAuth (currently) to get an Observable<firebase.User | null> is using the user property:

AngularFireAuth.user provides you an Observable<User|null> to monitor your application’s authentication State.

So instead of this:

You need to do this:

user: Observable<firebase.User|null>;

constructor(private afAuth : AngularFireAuth) {
  this.user = afAuth.user;

I tried
this.user = afAuth.user;
but it’s not working. Please help

Hi Abhik

May I know which video you are at??
Also ask your question separately so that I can figure out what kind of help you are looking for…

I also get stuck very often, we can help one another

Hi Ahmed,

Thanks for your reply. Please connect me We can help each other. Can also connect in 7975817054 if in India.