Reputation: 27
So here is the authService.ts :
user$: Observable<firebase.User>
constructor(private afAuth: AngularFireAuth) {
this.user$ = afAuth.authState ; //<-------- here's the problem
}```
Upvotes: 2
Views: 4845
Reputation: 295
I solved this as below
First I add .map<firebase.User>()
then I add <firebase.User | null>
This gave me error on .map
method in VS Code but on this.user$ = afAuth.authState;
error was removed.
So I saved file and removed .map
.
Upvotes: 0
Reputation: 11
I am using vanilla script so I had to made custom observable to achieve that
this.userob=new Observable(observe=>{
auth.onAuthStateChanged(x=>{
observe.next(x);
})
})
Upvotes: 1
Reputation: 14740
It depends on your intention, do you want to allow null
?
If so, just change the typing on your user$
:
user$: Observable<firebase.User|null>
If you don't want null, you could filter out null emissions:
this.user$ = afAuth.authState.pipe(
filter(u => !!u)
)
Upvotes: 2