@@ -76,7 +76,7 @@ export class AngularFireAuth {
76
76
) {
77
77
const schedulers = new ɵAngularFireSchedulers ( zone ) ;
78
78
const keepUnstableUntilFirst = ɵkeepUnstableUntilFirstFactory ( schedulers ) ;
79
- const logins = new Subject < firebase . auth . UserCredential > ( ) ;
79
+ const logins = new Subject < Required < firebase . auth . UserCredential > > ( ) ;
80
80
81
81
const auth = of ( undefined ) . pipe (
82
82
observeOn ( schedulers . outsideAngular ) ,
@@ -86,7 +86,7 @@ export class AngularFireAuth {
86
86
const useEmulator : UseEmulatorArguments | null = _useEmulator ;
87
87
const settings : firebase . auth . AuthSettings | null = _settings ;
88
88
return ɵfetchInstance ( `${ app . name } .auth` , 'AngularFireAuth' , app , ( ) => {
89
- const auth = app . auth ( ) ;
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
92
auth . useEmulator ( `http://${ useEmulator . join ( ':' ) } ` ) ;
@@ -128,14 +128,17 @@ export class AngularFireAuth {
128
128
// a user is signed in
129
129
switchMap ( auth => auth . getRedirectResult ( ) . then ( ( ) => auth , ( ) => auth ) ) ,
130
130
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 )
132
134
) ;
133
135
134
136
this . user = auth . pipe (
135
137
// see comment on authState
136
138
switchMap ( auth => auth . getRedirectResult ( ) . then ( ( ) => auth , ( ) => auth ) ) ,
137
139
switchMap ( auth => zone . runOutsideAngular ( ( ) => new Observable < firebase . User | null > ( auth . onIdTokenChanged . bind ( auth ) ) ) ) ,
138
- keepUnstableUntilFirst
140
+ keepUnstableUntilFirst ,
141
+ shareReplay ( 1 ) // see authState
139
142
) ;
140
143
141
144
this . idToken = this . user . pipe (
@@ -152,10 +155,12 @@ export class AngularFireAuth {
152
155
logins ,
153
156
// pipe in null authState to make credential zipable, just a weird devexp if
154
157
// 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
+ ) ) ,
157
160
// handle the { user: { } } when a user is already logged in, rather have null
158
161
map ( credential => credential ?. user ? credential : null ) ,
162
+ keepUnstableUntilFirst ,
163
+ shareReplay ( 1 )
159
164
) ;
160
165
161
166
}
@@ -166,7 +171,8 @@ export class AngularFireAuth {
166
171
// this will give us the user credential, push onto the logins Subject
167
172
// to be consumed in .credential
168
173
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 ) ) ;
170
176
}
171
177
}
172
178
} } ) ;
0 commit comments