Skip to content

Commit 8ea8934

Browse files
committed
Cleanup
1 parent 75d2faf commit 8ea8934

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,28 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
234234
'FirebaseServerApp could not login user with provided authIdToken: ',
235235
err
236236
);
237+
await this.directlySetCurrentUser(null);
237238
}
238239
}
239240

240241
private async initializeCurrentUser(
241242
popupRedirectResolver?: PopupRedirectResolver
242243
): 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+
243259
// First check to see if we have a pending redirect event.
244260
const previouslyStoredUser =
245261
(await this.assertedPersistence.getCurrentUser()) as UserInternal | null;
@@ -264,16 +280,6 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
264280
}
265281
}
266282

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-
277283
// If no user in persistence, there is no current user. Set to null.
278284
if (!futureCurrentUser) {
279285
return this.directlySetCurrentUser(null);

0 commit comments

Comments
 (0)