Skip to content

Commit c3ce295

Browse files
authored
Merge pull request #19521 from mozilla/FXA-12478
fix(settings): General app error with invalid jwt on ARK delete
2 parents 415f56b + f1798ae commit c3ce295

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

packages/fxa-settings/src/components/Settings/UnitRowRecoveryKey/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import React, { useCallback, useState } from 'react';
6-
import { useErrorHandler } from 'react-error-boundary';
76
import { useBooleanState } from 'fxa-react/lib/hooks';
87
import { useAccount, useAlertBar, useFtlMsgResolver } from '../../../models';
98
import { logViewEvent } from '../../../lib/metrics';
@@ -14,12 +13,14 @@ import { ButtonIconTrash } from '../ButtonIcon';
1413
import { SETTINGS_PATH } from '../../../constants';
1514
import { FtlMsg } from 'fxa-react/lib/utils';
1615
import GleanMetrics from '../../../lib/glean';
17-
import { isInvalidJwtError } from '../../../lib/mfa-guard-utils';
16+
import {
17+
clearMfaAndJwtCacheOnInvalidJwt,
18+
isInvalidJwtError,
19+
} from '../../../lib/mfa-guard-utils';
1820
import { MfaGuard } from '../MfaGuard';
1921

2022
export const UnitRowRecoveryKey = () => {
2123
const account = useAccount();
22-
const errorHandler = useErrorHandler();
2324

2425
const recoveryKey = account.recoveryKey.exists;
2526
const alertBar = useAlertBar();
@@ -39,14 +40,17 @@ export const UnitRowRecoveryKey = () => {
3940
);
4041
logViewEvent('flow.settings.account-recovery', 'confirm-revoke.success');
4142
} catch (e) {
42-
hideModal();
43-
4443
if (isInvalidJwtError(e)) {
4544
// JWT invalid/expired
46-
errorHandler(e);
45+
// We cannot route invalid-JWT errors from here through useErrorHandler,
46+
// because it throws above MfaErrorBoundary
47+
// so we clear the MFA and JWT cache manually
48+
// this will cause the MfaGuard to re-render and show the MfaModalDialog
49+
clearMfaAndJwtCacheOnInvalidJwt(e, 'recovery_key');
4750
return;
4851
}
49-
52+
// we only want to hide the modal if the error is not an invalid JWT error
53+
hideModal();
5054
alertBar.error(
5155
ftlMsgResolver.getMsg(
5256
'rk-remove-error-2',
@@ -57,7 +61,7 @@ export const UnitRowRecoveryKey = () => {
5761
} finally {
5862
setIsDeleting(false);
5963
}
60-
}, [account, hideModal, alertBar, ftlMsgResolver, errorHandler]);
64+
}, [account, hideModal, alertBar, ftlMsgResolver]);
6165

6266
const localizedDeleteRKIconButton = ftlMsgResolver.getMsg(
6367
'unit-row-recovery-key-delete-icon-button-title',

packages/fxa-settings/src/models/Account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ export class Account implements AccountData {
16351635
}
16361636
const hasJwt = JwtTokenCache.hasToken(token, scope);
16371637
if (!hasJwt) {
1638-
throw AuthUiErrors.INVALID_REQUEST_SIGNATURE;
1638+
throw AuthUiErrors.INVALID_TOKEN;
16391639
}
16401640

16411641
return JwtTokenCache.getToken(token, scope);

0 commit comments

Comments
 (0)