'How to combine switchMap with combineLatest

I need to combine UserRole from RealtimeDatabase and User from FirebaseAuth. How do I combine these two queries, one of which is based on the other? The following code allows you to download a single file or two files simultaneously.

from(this.auth.signInWithEmailAndPassword(email, password))
      .pipe(
        switchMap((result: any) => this.getUserRole(result.user.uid)),
        take(1)
      )
      .subscribe(console.warn);

or

combineLatest([x1, this.getUserRole('8OKFSRBeZ3dY4ecQVn8AyJHBQim2')])
  .pipe(tap(console.warn))
.subscribe();


Solution 1:[1]

Does it work for you? Note: combineLatest may be not the best for the case, you can try frokJoin.

from(this.auth.signInWithEmailAndPassword(email, password))
    .pipe(
        switchMap((result: any) => combineLatest(of(result.user), this.getUserRole(result.user.uid))),
    )
    .subscribe(console.warn);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leon