@@ -234,12 +234,28 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
234
234
'FirebaseServerApp could not login user with provided authIdToken: ' ,
235
235
err
236
236
) ;
237
+ await this . directlySetCurrentUser ( null ) ;
237
238
}
238
239
}
239
240
240
241
private async initializeCurrentUser (
241
242
popupRedirectResolver ?: PopupRedirectResolver
242
243
) : Promise < void > {
244
+ if ( _isFirebaseServerApp ( this . app ) ) {
245
+ const idToken = this . app . settings . authIdToken ;
246
+ if ( idToken ) {
247
+ // Start the auth operation in the next tick to allow a moment for the customer's app to
248
+ // attach an emulator, if desired.
249
+ return new Promise < void > ( resolve => {
250
+ setTimeout ( ( ) =>
251
+ this . loadUserFromIdToken ( idToken ) . then ( resolve , resolve )
252
+ ) ;
253
+ } ) ;
254
+ } else {
255
+ return this . directlySetCurrentUser ( null ) ;
256
+ }
257
+ }
258
+
243
259
// First check to see if we have a pending redirect event.
244
260
const previouslyStoredUser =
245
261
( await this . assertedPersistence . getCurrentUser ( ) ) as UserInternal | null ;
@@ -264,16 +280,6 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
264
280
}
265
281
}
266
282
267
- if ( _isFirebaseServerApp ( this . app ) ) {
268
- const idToken = this . app . settings . authIdToken ;
269
- if ( idToken ) {
270
- // Start the auth operation in the next tick to allow a moment for the customer's app to
271
- // attach an emulator, if desired.
272
- setTimeout ( ( ) => void this . loadUserFromIdToken ( idToken ) , 0 ) ;
273
- return ;
274
- }
275
- }
276
-
277
283
// If no user in persistence, there is no current user. Set to null.
278
284
if ( ! futureCurrentUser ) {
279
285
return this . directlySetCurrentUser ( null ) ;
0 commit comments