1
- import { FirebaseAuth , User } from '@firebase/auth-types' ;
1
+ import { FirebaseAuth , User , IdTokenResult } from '@firebase/auth-types' ;
2
2
import { FirebaseOptions , FirebaseAppConfig } from '@firebase/app-types' ;
3
3
import { Injectable , Inject , Optional , NgZone , PLATFORM_ID } from '@angular/core' ;
4
4
import { Observable , of , from } from 'rxjs' ;
@@ -16,15 +16,27 @@ export class AngularFireAuth {
16
16
public readonly auth : FirebaseAuth ;
17
17
18
18
/**
19
- * Observable of authentication state; as of 4.0 this is only triggered via sign-in/out
19
+ * Observable of authentication state; as of Firebase 4.0 this is only triggered via sign-in/out
20
20
*/
21
21
public readonly authState : Observable < User | null > ;
22
22
23
23
/**
24
- * Observable of the signed-in user's ID token; which includes sign-in, sign-out, and token refresh events
24
+ * Observable of the currently signed-in user's JWT token used to identify the user to a Firebase service (or null).
25
25
*/
26
26
public readonly idToken : Observable < string | null > ;
27
27
28
+ /**
29
+ * Observable of the currently signed-in user (or null).
30
+ */
31
+ public readonly user : Observable < User | null > ;
32
+
33
+ /**
34
+ * Observable of the currently signed-in user's IdTokenResult object which contains the ID token JWT string and other
35
+ * helper properties for getting different data associated with the token as well as all the decoded payload claims
36
+ * (or null).
37
+ */
38
+ public readonly idTokenResult : Observable < IdTokenResult | null > ;
39
+
28
40
constructor (
29
41
@Inject ( FirebaseOptionsToken ) options :FirebaseOptions ,
30
42
@Optional ( ) @Inject ( FirebaseAppConfigToken ) config :FirebaseAppConfig ,
@@ -47,16 +59,22 @@ export class AngularFireAuth {
47
59
)
48
60
) ;
49
61
50
- this . idToken = scheduler . keepUnstableUntilFirst (
62
+ this . user = scheduler . keepUnstableUntilFirst (
51
63
scheduler . runOutsideAngular (
52
64
new Observable ( subscriber => {
53
65
const unsubscribe = this . auth . onIdTokenChanged ( subscriber ) ;
54
66
return { unsubscribe } ;
55
67
} )
56
68
)
57
- ) . pipe ( switchMap ( ( user :User ) => {
69
+ ) ;
70
+
71
+ this . idToken = this . user . pipe ( switchMap ( user => {
58
72
return user ? from ( user . getIdToken ( ) ) : of ( null )
59
- } ) ) ;
73
+ } ) ) ;
74
+
75
+ this . idTokenResult = this . user . pipe ( switchMap ( user => {
76
+ return user ? from ( user . getIdTokenResult ( ) ) : of ( null )
77
+ } ) ) ;
60
78
}
61
79
62
80
}
0 commit comments