Search code examples
angularrxjsfirebase-authenticationangularfire

AngularFireAuth.user observable won't emit when placed in withLatestFrom RxJS operator


The AngularFireAuth.user observable works fine if it is the source observable e.g.

this.AngularFireAuth.user.subscribe((u) => console.log(u))

but blocks my observable stream if I place it in the withLatestFrom operator, e.g.

of("test")
.pipe(
   tap(console.log), // log showing up
   withLatestFrom(this.AngularFireAuth.user),
   tap(console.log)  // log not showing up
   ).subscribe()

What am I doing wrong and how can I get around it? I need the current auth state but the source observable needs to be a different observable than that.


Solution

  • that is because user stream didn't emit anything yet. I believe the easiest case to fix this problem would be to add startsWith(null) for the user stream

    withLatestFrom(this.AngularFireAuth.user.pipe(startsWith(null)))