Skip to content

Commit 2c90aec

Browse files
authored
[Auth] Remove background error throwing in initialization (#5308)
* Fix auth initialization issue * Formatting * Make sure a test would fail * Formatting
1 parent fb27f50 commit 2c90aec

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
7979
private idTokenSubscription = new Subscription<User>(this);
8080
private redirectUser: UserInternal | null = null;
8181
private isProactiveRefreshEnabled = false;
82-
private redirectInitializerError: Error | null = null;
8382

8483
// Any network calls will set this to true and prevent subsequent emulator
8584
// initialization
@@ -88,10 +87,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
8887
_deleted = false;
8988
_initializationPromise: Promise<void> | null = null;
9089
_popupRedirectResolver: PopupRedirectResolverInternal | null = null;
91-
_errorFactory: ErrorFactory<
92-
AuthErrorCode,
93-
AuthErrorParams
94-
> = _DEFAULT_AUTH_ERROR_FACTORY;
90+
_errorFactory: ErrorFactory<AuthErrorCode, AuthErrorParams> =
91+
_DEFAULT_AUTH_ERROR_FACTORY;
9592
readonly name: string;
9693

9794
// Tracks the last notified UID for state change listeners to prevent
@@ -150,12 +147,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
150147
this._isInitialized = true;
151148
});
152149

153-
// After initialization completes, throw any error caused by redirect flow
154-
return this._initializationPromise.then(() => {
155-
if (this.redirectInitializerError) {
156-
throw this.redirectInitializerError;
157-
}
158-
});
150+
return this._initializationPromise;
159151
}
160152

161153
/**
@@ -191,7 +183,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
191183
popupRedirectResolver?: PopupRedirectResolver
192184
): Promise<void> {
193185
// First check to see if we have a pending redirect event.
194-
let storedUser = (await this.assertedPersistence.getCurrentUser()) as UserInternal | null;
186+
let storedUser =
187+
(await this.assertedPersistence.getCurrentUser()) as UserInternal | null;
195188
if (popupRedirectResolver && this.config.authDomain) {
196189
await this.getOrInitRedirectPersistenceManager();
197190
const redirectUserEventId = this.redirectUser?._redirectEventId;
@@ -267,7 +260,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
267260
true
268261
);
269262
} catch (e) {
270-
this.redirectInitializerError = e;
263+
// Swallow any errors here; the code can retrieve them in
264+
// getRedirectResult().
271265
await this._setRedirectUser(null);
272266
}
273267

@@ -419,7 +413,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
419413
[_getInstance(resolver._redirectPersistence)],
420414
KeyName.REDIRECT_USER
421415
);
422-
this.redirectUser = await this.redirectPersistenceManager.getCurrentUser();
416+
this.redirectUser =
417+
await this.redirectPersistenceManager.getCurrentUser();
423418
}
424419

425420
return this.redirectPersistenceManager;

packages-exp/auth-exp/src/platform_browser/auth.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ describe('core/auth/initializeAuth', () => {
328328
stub._remove.returns(Promise.resolve());
329329
completeRedirectFnStub.returns(Promise.reject(new Error('no')));
330330

331+
// Manually initialize auth to make sure no error is thrown,
332+
// since the _initializeAuthInstance function floats
333+
const auth = new AuthImpl(FAKE_APP, {
334+
apiKey: FAKE_APP.options.apiKey!,
335+
apiHost: DefaultConfig.API_HOST,
336+
apiScheme: DefaultConfig.API_SCHEME,
337+
tokenApiHost: DefaultConfig.TOKEN_API_HOST,
338+
authDomain: FAKE_APP.options.authDomain,
339+
clientPlatform: ClientPlatform.BROWSER,
340+
sdkClientVersion: _getClientVersion(ClientPlatform.BROWSER)
341+
});
342+
await expect(
343+
auth._initializeWithPersistence(
344+
[_getInstance(inMemoryPersistence)],
345+
browserPopupRedirectResolver
346+
)
347+
).to.not.be.rejected;
348+
331349
await initAndWait([inMemoryPersistence], browserPopupRedirectResolver);
332350
expect(stub._remove).to.have.been.called;
333351
});

0 commit comments

Comments
 (0)