33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55import React , { useCallback , useState } from 'react' ;
6- import { useErrorHandler } from 'react-error-boundary' ;
76import { useBooleanState } from 'fxa-react/lib/hooks' ;
87import { useAccount , useAlertBar , useFtlMsgResolver } from '../../../models' ;
98import { logViewEvent } from '../../../lib/metrics' ;
@@ -14,12 +13,14 @@ import { ButtonIconTrash } from '../ButtonIcon';
1413import { SETTINGS_PATH } from '../../../constants' ;
1514import { FtlMsg } from 'fxa-react/lib/utils' ;
1615import GleanMetrics from '../../../lib/glean' ;
17- import { isInvalidJwtError } from '../../../lib/mfa-guard-utils' ;
16+ import {
17+ clearMfaAndJwtCacheOnInvalidJwt ,
18+ isInvalidJwtError ,
19+ } from '../../../lib/mfa-guard-utils' ;
1820import { MfaGuard } from '../MfaGuard' ;
1921
2022export 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' ,
0 commit comments