Skip to content

Commit ef9b649

Browse files
committed
Address PR comments
1 parent 202a114 commit ef9b649

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
182182
}
183183

184184
// Update current Auth state. Either a new login or logout.
185-
await this._updateCurrentUser(user);
185+
// Skip blocking callbacks, they should not apply to a change in another tab.
186+
await this._updateCurrentUser(user, /* skipBeforeStateCallbacks */ true);
186187
}
187188

188189
private async initializeCurrentUser(
@@ -314,7 +315,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
314315
return this._updateCurrentUser(user && user._clone(this));
315316
}
316317

317-
async _updateCurrentUser(user: User | null): Promise<void> {
318+
async _updateCurrentUser(user: User | null, skipBeforeStateCallbacks: boolean = false): Promise<void> {
318319
if (this._deleted) {
319320
return;
320321
}
@@ -325,7 +326,10 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
325326
AuthErrorCode.TENANT_ID_MISMATCH
326327
);
327328
}
328-
await this._runBeforeStateCallbacks(user);
329+
330+
if (!skipBeforeStateCallbacks) {
331+
await this._runBeforeStateCallbacks(user);
332+
}
329333

330334
return this.queue(async () => {
331335
await this.directlySetCurrentUser(user as UserInternal | null);
@@ -339,18 +343,22 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
339343
await beforeStateCallback(user);
340344
}
341345
} catch (e) {
342-
throw this._errorFactory.create(AuthErrorCode.LOGIN_BLOCKED, { message: e.message });
346+
throw this._errorFactory.create(
347+
AuthErrorCode.LOGIN_BLOCKED, { originalMessage: e.message });
343348
}
344349
}
345350

346351
async signOut(): Promise<void> {
352+
// Run first, to block _setRedirectUser() if any callbacks fail.
347353
await this._runBeforeStateCallbacks(null);
348354
// Clear the redirect user when signOut is called
349355
if (this.redirectPersistenceManager || this._popupRedirectResolver) {
350356
await this._setRedirectUser(null);
351357
}
352358

353-
return this._updateCurrentUser(null);
359+
// Prevent callbacks from being called again in _updateCurrentUser, as
360+
// they were already called in the first line.
361+
return this._updateCurrentUser(null, /* skipBeforeStateCallbacks */ true);
354362
}
355363

356364
setPersistence(persistence: Persistence): Promise<void> {

packages/auth/src/core/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
246246
'The verification ID used to create the phone auth credential is invalid.',
247247
[AuthErrorCode.INVALID_TENANT_ID]:
248248
"The Auth instance's tenant ID is invalid.",
249-
[AuthErrorCode.LOGIN_BLOCKED]: "Login blocked by user-provided method.",
249+
[AuthErrorCode.LOGIN_BLOCKED]: "Login blocked by user-provided method: {$originalMessage}",
250250
[AuthErrorCode.MISSING_ANDROID_PACKAGE_NAME]:
251251
'An Android Package Name must be provided if the Android App is required to be installed.',
252252
[AuthErrorCode.MISSING_AUTH_DOMAIN]:
@@ -430,7 +430,7 @@ export interface AuthErrorParams extends GenericAuthErrorParams {
430430
[AuthErrorCode.ARGUMENT_ERROR]: { appName?: AppName };
431431
[AuthErrorCode.DEPENDENT_SDK_INIT_BEFORE_AUTH]: { appName?: AppName };
432432
[AuthErrorCode.INTERNAL_ERROR]: { appName?: AppName };
433-
[AuthErrorCode.LOGIN_BLOCKED]: { message?: string };
433+
[AuthErrorCode.LOGIN_BLOCKED]: { appName?: AppName, originalMessage?: string };
434434
[AuthErrorCode.OPERATION_NOT_SUPPORTED]: { appName?: AppName };
435435
[AuthErrorCode.NO_AUTH_EVENT]: { appName?: AppName };
436436
[AuthErrorCode.MFA_REQUIRED]: {

0 commit comments

Comments
 (0)