1- import { FirebaseAuth , User } from '@firebase/auth-types' ;
1+ import { FirebaseAuth , User , IdTokenResult } from '@firebase/auth-types' ;
22import { FirebaseOptions , FirebaseAppConfig } from '@firebase/app-types' ;
33import { Injectable , Inject , Optional , NgZone , PLATFORM_ID } from '@angular/core' ;
44import { Observable , of , from } from 'rxjs' ;
@@ -16,15 +16,27 @@ export class AngularFireAuth {
1616 public readonly auth : FirebaseAuth ;
1717
1818 /**
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
2020 */
2121 public readonly authState : Observable < User | null > ;
2222
2323 /**
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).
2525 */
2626 public readonly idToken : Observable < string | null > ;
2727
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+
2840 constructor (
2941 @Inject ( FirebaseOptionsToken ) options :FirebaseOptions ,
3042 @Optional ( ) @Inject ( FirebaseAppConfigToken ) config :FirebaseAppConfig ,
@@ -47,16 +59,22 @@ export class AngularFireAuth {
4759 )
4860 ) ;
4961
50- this . idToken = scheduler . keepUnstableUntilFirst (
62+ this . user = scheduler . keepUnstableUntilFirst (
5163 scheduler . runOutsideAngular (
5264 new Observable ( subscriber => {
5365 const unsubscribe = this . auth . onIdTokenChanged ( subscriber ) ;
5466 return { unsubscribe } ;
5567 } )
5668 )
57- ) . pipe ( switchMap ( ( user :User ) => {
69+ ) ;
70+
71+ this . idToken = this . user . pipe ( switchMap ( user => {
5872 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+ } ) ) ;
6078 }
6179
6280}
0 commit comments