@@ -76,7 +76,7 @@ export class AngularFireAuth {
7676 ) {
7777 const schedulers = new ɵAngularFireSchedulers ( zone ) ;
7878 const keepUnstableUntilFirst = ɵkeepUnstableUntilFirstFactory ( schedulers ) ;
79- const logins = new Subject < firebase . auth . UserCredential > ( ) ;
79+ const logins = new Subject < Required < firebase . auth . UserCredential > > ( ) ;
8080
8181 const auth = of ( undefined ) . pipe (
8282 observeOn ( schedulers . outsideAngular ) ,
@@ -86,7 +86,7 @@ export class AngularFireAuth {
8686 const useEmulator : UseEmulatorArguments | null = _useEmulator ;
8787 const settings : firebase . auth . AuthSettings | null = _settings ;
8888 return ɵfetchInstance ( `${ app . name } .auth` , 'AngularFireAuth' , app , ( ) => {
89- const auth = app . auth ( ) ;
89+ const auth = zone . runOutsideAngular ( ( ) => app . auth ( ) ) ;
9090 if ( useEmulator ) {
9191 // Firebase Auth doesn't conform to the useEmulator convention, let's smooth that over
9292 auth . useEmulator ( `http://${ useEmulator . join ( ':' ) } ` ) ;
@@ -128,14 +128,17 @@ export class AngularFireAuth {
128128 // a user is signed in
129129 switchMap ( auth => auth . getRedirectResult ( ) . then ( ( ) => auth , ( ) => auth ) ) ,
130130 switchMap ( auth => zone . runOutsideAngular ( ( ) => new Observable < firebase . User | null > ( auth . onAuthStateChanged . bind ( auth ) ) ) ) ,
131- keepUnstableUntilFirst
131+ keepUnstableUntilFirst ,
132+ // TODO figure out why I needed share, perhaps it's the observable construction?
133+ shareReplay ( 1 )
132134 ) ;
133135
134136 this . user = auth . pipe (
135137 // see comment on authState
136138 switchMap ( auth => auth . getRedirectResult ( ) . then ( ( ) => auth , ( ) => auth ) ) ,
137139 switchMap ( auth => zone . runOutsideAngular ( ( ) => new Observable < firebase . User | null > ( auth . onIdTokenChanged . bind ( auth ) ) ) ) ,
138- keepUnstableUntilFirst
140+ keepUnstableUntilFirst ,
141+ shareReplay ( 1 ) // see authState
139142 ) ;
140143
141144 this . idToken = this . user . pipe (
@@ -152,10 +155,12 @@ export class AngularFireAuth {
152155 logins ,
153156 // pipe in null authState to make credential zipable, just a weird devexp if
154157 // authState and user go null to still have a credential
155- this . authState . pipe ( filter ( it => ! it ) ) )
156- ) ,
158+ this . authState . pipe ( filter ( it => ! it ) )
159+ ) ) ,
157160 // handle the { user: { } } when a user is already logged in, rather have null
158161 map ( credential => credential ?. user ? credential : null ) ,
162+ keepUnstableUntilFirst ,
163+ shareReplay ( 1 )
159164 ) ;
160165
161166 }
@@ -166,7 +171,8 @@ export class AngularFireAuth {
166171 // this will give us the user credential, push onto the logins Subject
167172 // to be consumed in .credential
168173 if ( name . startsWith ( 'signIn' ) || name . startsWith ( 'createUser' ) ) {
169- val . then ( ( user : firebase . auth . UserCredential ) => logins . next ( user ) ) ;
174+ // TODO fix the types, the trouble is UserCredential has everything optional
175+ val . then ( ( user : firebase . auth . UserCredential ) => logins . next ( user as any ) ) ;
170176 }
171177 }
172178 } } ) ;
0 commit comments