@@ -13,17 +13,17 @@ import {
13
13
ɵkeepUnstableUntilFirstFactory ,
14
14
ɵapplyMixins
15
15
} from '@angular/fire' ;
16
- import firebase from 'firebase/app ' ;
16
+ import { Auth , AuthSettings , UserCredential , User , IdTokenResult , Persistence , getRedirectResult , useAuthEmulator , setPersistence } from 'firebase/auth ' ;
17
17
import { isPlatformServer } from '@angular/common' ;
18
18
import { proxyPolyfillCompat } from './base' ;
19
19
import { ɵfetchInstance } from '@angular/fire' ;
20
20
21
- export interface AngularFireAuth extends ɵPromiseProxy < firebase . auth . Auth > { }
21
+ export interface AngularFireAuth extends ɵPromiseProxy < Auth > { }
22
22
23
23
type UseEmulatorArguments = [ string , number ] ;
24
24
export const USE_EMULATOR = new InjectionToken < UseEmulatorArguments > ( 'angularfire2.auth.use-emulator' ) ;
25
25
26
- export const SETTINGS = new InjectionToken < firebase . auth . AuthSettings > ( 'angularfire2.auth.settings' ) ;
26
+ export const SETTINGS = new InjectionToken < AuthSettings > ( 'angularfire2.auth.settings' ) ;
27
27
export const TENANT_ID = new InjectionToken < string > ( 'angularfire2.auth.tenant-id' ) ;
28
28
export const LANGUAGE_CODE = new InjectionToken < string > ( 'angularfire2.auth.langugage-code' ) ;
29
29
export const USE_DEVICE_LANGUAGE = new InjectionToken < boolean > ( 'angularfire2.auth.use-device-language' ) ;
@@ -37,7 +37,7 @@ export class AngularFireAuth {
37
37
/**
38
38
* Observable of authentication state; as of Firebase 4.0 this is only triggered via sign-in/out
39
39
*/
40
- public readonly authState : Observable < firebase . User | null > ;
40
+ public readonly authState : Observable < User | null > ;
41
41
42
42
/**
43
43
* Observable of the currently signed-in user's JWT token used to identify the user to a Firebase service (or null).
@@ -47,19 +47,19 @@ export class AngularFireAuth {
47
47
/**
48
48
* Observable of the currently signed-in user (or null).
49
49
*/
50
- public readonly user : Observable < firebase . User | null > ;
50
+ public readonly user : Observable < User | null > ;
51
51
52
52
/**
53
53
* Observable of the currently signed-in user's IdTokenResult object which contains the ID token JWT string and other
54
54
* helper properties for getting different data associated with the token as well as all the decoded payload claims
55
55
* (or null).
56
56
*/
57
- public readonly idTokenResult : Observable < firebase . auth . IdTokenResult | null > ;
57
+ public readonly idTokenResult : Observable < IdTokenResult | null > ;
58
58
59
59
/**
60
60
* Observable of the currently signed-in user's credential, or null
61
61
*/
62
- public readonly credential : Observable < Required < firebase . auth . UserCredential > | null > ;
62
+ public readonly credential : Observable < Required < UserCredential > | null > ;
63
63
64
64
constructor (
65
65
@Inject ( FIREBASE_OPTIONS ) options : FirebaseOptions ,
@@ -68,28 +68,28 @@ export class AngularFireAuth {
68
68
@Inject ( PLATFORM_ID ) platformId : Object ,
69
69
zone : NgZone ,
70
70
@Optional ( ) @Inject ( USE_EMULATOR ) _useEmulator : any , // can't use the tuple here
71
- @Optional ( ) @Inject ( SETTINGS ) _settings : any , // can't use firebase.auth. AuthSettings here
71
+ @Optional ( ) @Inject ( SETTINGS ) _settings : any , // can't use AuthSettings here
72
72
@Optional ( ) @Inject ( TENANT_ID ) tenantId : string | null ,
73
73
@Optional ( ) @Inject ( LANGUAGE_CODE ) languageCode : string | null ,
74
74
@Optional ( ) @Inject ( USE_DEVICE_LANGUAGE ) useDeviceLanguage : boolean | null ,
75
- @Optional ( ) @Inject ( PERSISTENCE ) persistence : string | null ,
75
+ @Optional ( ) @Inject ( PERSISTENCE ) persistence : Persistence | null ,
76
76
) {
77
77
const schedulers = new ɵAngularFireSchedulers ( zone ) ;
78
78
const keepUnstableUntilFirst = ɵkeepUnstableUntilFirstFactory ( schedulers ) ;
79
- const logins = new Subject < Required < firebase . auth . UserCredential > > ( ) ;
79
+ const logins = new Subject < Required < UserCredential > > ( ) ;
80
80
81
81
const auth = of ( undefined ) . pipe (
82
82
observeOn ( schedulers . outsideAngular ) ,
83
83
switchMap ( ( ) => zone . runOutsideAngular ( ( ) => import ( 'firebase/auth' ) ) ) ,
84
84
map ( ( ) => ɵfirebaseAppFactory ( options , zone , nameOrConfig ) ) ,
85
85
map ( app => zone . runOutsideAngular ( ( ) => {
86
86
const useEmulator : UseEmulatorArguments | null = _useEmulator ;
87
- const settings : firebase . auth . AuthSettings | null = _settings ;
87
+ const settings : AuthSettings | null = _settings ;
88
88
return ɵfetchInstance ( `${ app . name } .auth` , 'AngularFireAuth' , app , ( ) => {
89
89
const auth = zone . runOutsideAngular ( ( ) => app . auth ( ) ) ;
90
90
if ( useEmulator ) {
91
91
// Firebase Auth doesn't conform to the useEmulator convention, let's smooth that over
92
- auth . useEmulator ( `http://${ useEmulator . join ( ':' ) } ` ) ;
92
+ useAuthEmulator ( auth , `http://${ useEmulator . join ( ':' ) } ` ) ;
93
93
}
94
94
if ( tenantId ) {
95
95
auth . tenantId = tenantId ;
@@ -98,11 +98,12 @@ export class AngularFireAuth {
98
98
if ( useDeviceLanguage ) {
99
99
auth . useDeviceLanguage ( ) ;
100
100
}
101
- if ( settings ) {
102
- auth . settings = settings ;
103
- }
101
+ // TODO(team): We need to initalizeAuth with settings in the NgModule
102
+ // if (settings) {
103
+ // auth.settings = settings;
104
+ // }
104
105
if ( persistence ) {
105
- auth . setPersistence ( persistence ) ;
106
+ setPersistence ( auth , persistence ) ;
106
107
}
107
108
return auth ;
108
109
} , [ useEmulator , tenantId , languageCode , useDeviceLanguage , settings , persistence ] ) ;
@@ -124,7 +125,7 @@ export class AngularFireAuth {
124
125
const _ = auth . pipe ( first ( ) ) . subscribe ( ) ;
125
126
126
127
const redirectResult = auth . pipe (
127
- switchMap ( auth => auth . getRedirectResult ( ) . then ( it => it , ( ) => null ) ) ,
128
+ switchMap ( auth => getRedirectResult ( auth ) . then ( it => it , ( ) => null ) ) ,
128
129
keepUnstableUntilFirst ,
129
130
shareReplay ( { bufferSize : 1 , refCount : false } ) ,
130
131
) ;
@@ -170,7 +171,7 @@ export class AngularFireAuth {
170
171
) . pipe (
171
172
// handle the { user: { } } when a user is already logged in, rather have null
172
173
// TODO handle the type corcersion better
173
- map ( credential => credential ?. user ? credential as Required < firebase . auth . UserCredential > : null ) ,
174
+ map ( credential => credential ?. user ? credential as Required < UserCredential > : null ) ,
174
175
subscribeOn ( schedulers . outsideAngular ) ,
175
176
observeOn ( schedulers . insideAngular ) ,
176
177
) ;
@@ -184,7 +185,7 @@ export class AngularFireAuth {
184
185
// to be consumed in .credential
185
186
if ( name . startsWith ( 'signIn' ) || name . startsWith ( 'createUser' ) ) {
186
187
// TODO fix the types, the trouble is UserCredential has everything optional
187
- val . then ( ( user : firebase . auth . UserCredential ) => logins . next ( user as any ) ) ;
188
+ val . then ( ( user : UserCredential ) => logins . next ( user as any ) ) ;
188
189
}
189
190
}
190
191
} } ) ;
0 commit comments