@@ -19,8 +19,8 @@ import {AngularFireAuth} from '@angular/fire/compat/auth';
19
19
import { AngularFireFunctions } from '@angular/fire/compat/functions' ;
20
20
import { GoogleAuthProvider } from 'firebase/auth' ;
21
21
import firebase from 'firebase/compat/app' ;
22
- import { Observable , firstValueFrom , from } from 'rxjs' ;
23
- import { map , shareReplay , switchMap } from 'rxjs/operators' ;
22
+ import { Observable , Subject , firstValueFrom , from } from 'rxjs' ;
23
+ import { map , mergeWith , shareReplay , switchMap } from 'rxjs/operators' ;
24
24
25
25
import { AclEntry } from 'app/models/acl-entry.model' ;
26
26
import { DataCollectionStrategy , Job } from 'app/models/job.model' ;
@@ -52,6 +52,7 @@ export const ROLE_OPTIONS = [
52
52
} )
53
53
export class AuthService {
54
54
private user$ : Observable < User > ;
55
+ private tokenChanged$ = new Subject < firebase . User | null > ( ) ;
55
56
private currentUser ! : User ;
56
57
private hasAcceptedTos = false ;
57
58
@@ -62,7 +63,9 @@ export class AuthService {
62
63
private functions : AngularFireFunctions ,
63
64
private httpClientService : HttpClientService
64
65
) {
66
+ this . afAuth . onIdTokenChanged ( user => this . tokenChanged$ . next ( user ) ) ;
65
67
this . user$ = this . afAuth . authState . pipe (
68
+ mergeWith ( this . tokenChanged$ ) ,
66
69
switchMap ( user => from ( this . onAuthStateChange ( user ) ) ) ,
67
70
map ( user => user || ANONYMOUS_USER ) ,
68
71
// Cache last authenticated user so that late subscribers receive it as well.
0 commit comments