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' ;
67import { useBooleanState } from 'fxa-react/lib/hooks' ;
78import { useAccount , useAlertBar , useFtlMsgResolver } from '../../../models' ;
89import { logViewEvent } from '../../../lib/metrics' ;
@@ -13,9 +14,12 @@ import { ButtonIconTrash } from '../ButtonIcon';
1314import { SETTINGS_PATH } from '../../../constants' ;
1415import { FtlMsg } from 'fxa-react/lib/utils' ;
1516import GleanMetrics from '../../../lib/glean' ;
17+ import { isInvalidJwtError } from '../../../lib/mfa-guard-utils' ;
18+ import { MfaGuard } from '../MfaGuard' ;
1619
1720export const UnitRowRecoveryKey = ( ) => {
1821 const account = useAccount ( ) ;
22+ const errorHandler = useErrorHandler ( ) ;
1923
2024 const recoveryKey = account . recoveryKey . exists ;
2125 const alertBar = useAlertBar ( ) ;
@@ -25,7 +29,7 @@ export const UnitRowRecoveryKey = () => {
2529
2630 const deleteRecoveryKey = useCallback ( async ( ) => {
2731 try {
28- await account . deleteRecoveryKey ( ) ;
32+ await account . deleteRecoveryKeyWithJwt ( ) ;
2933 hideModal ( ) ;
3034 alertBar . success (
3135 ftlMsgResolver . getMsg (
@@ -36,6 +40,13 @@ export const UnitRowRecoveryKey = () => {
3640 logViewEvent ( 'flow.settings.account-recovery' , 'confirm-revoke.success' ) ;
3741 } catch ( e ) {
3842 hideModal ( ) ;
43+
44+ if ( isInvalidJwtError ( e ) ) {
45+ // JWT invalid/expired
46+ errorHandler ( e ) ;
47+ return ;
48+ }
49+
3950 alertBar . error (
4051 ftlMsgResolver . getMsg (
4152 'rk-remove-error-2' ,
@@ -46,7 +57,7 @@ export const UnitRowRecoveryKey = () => {
4657 } finally {
4758 setIsDeleting ( false ) ;
4859 }
49- } , [ account , hideModal , alertBar , ftlMsgResolver ] ) ;
60+ } , [ account , hideModal , alertBar , ftlMsgResolver , errorHandler ] ) ;
5061
5162 const localizedDeleteRKIconButton = ftlMsgResolver . getMsg (
5263 'unit-row-recovery-key-delete-icon-button-title' ,
@@ -120,40 +131,42 @@ export const UnitRowRecoveryKey = () => {
120131 ) ;
121132 } }
122133 >
123- < Modal
124- onDismiss = { ( ) => {
125- hideModal ( ) ;
126- } }
127- onConfirm = { ( ) => {
128- setIsDeleting ( true ) ;
129- deleteRecoveryKey ( ) ;
130- logViewEvent (
131- 'flow.settings.account-recovery' ,
132- 'confirm-revoke.submit'
133- ) ;
134- } }
135- confirmBtnClassName = "cta-caution cta-base-p"
136- confirmText = { ftlMsgResolver . getMsg ( 'rk-action-remove' , 'Remove' ) }
137- headerId = "recovery-key-header"
138- descId = "recovery-key-desc"
139- isLoading = { isDeleting }
140- >
141- < FtlMsg id = "rk-remove-modal-heading-1" >
142- < h2
143- id = "recovery-key-header"
144- className = "font-bold text-xl text-center mb-2"
145- >
146- Remove account recovery key?
147- </ h2 >
148- </ FtlMsg >
149- < FtlMsg id = "rk-remove-modal-content-1" >
150- < p className = "my-6 text-center" >
151- In the event you reset your password, you wonʼt be able to use
152- your account recovery key to access your data. You canʼt undo
153- this action.
154- </ p >
155- </ FtlMsg >
156- </ Modal >
134+ < MfaGuard requiredScope = "recovery_key" >
135+ < Modal
136+ onDismiss = { ( ) => {
137+ hideModal ( ) ;
138+ } }
139+ onConfirm = { ( ) => {
140+ setIsDeleting ( true ) ;
141+ deleteRecoveryKey ( ) ;
142+ logViewEvent (
143+ 'flow.settings.account-recovery' ,
144+ 'confirm-revoke.submit'
145+ ) ;
146+ } }
147+ confirmBtnClassName = "cta-caution cta-base-p"
148+ confirmText = { ftlMsgResolver . getMsg ( 'rk-action-remove' , 'Remove' ) }
149+ headerId = "recovery-key-header"
150+ descId = "recovery-key-desc"
151+ isLoading = { isDeleting }
152+ >
153+ < FtlMsg id = "rk-remove-modal-heading-1" >
154+ < h2
155+ id = "recovery-key-header"
156+ className = "font-bold text-xl text-center mb-2"
157+ >
158+ Remove account recovery key?
159+ </ h2 >
160+ </ FtlMsg >
161+ < FtlMsg id = "rk-remove-modal-content-1" >
162+ < p className = "my-6 text-center" >
163+ In the event you reset your password, you wonʼt be able to use
164+ your account recovery key to access your data. You canʼt undo
165+ this action.
166+ </ p >
167+ </ FtlMsg >
168+ </ Modal >
169+ </ MfaGuard >
157170 </ VerifiedSessionGuard >
158171 ) }
159172 </ UnitRow >
0 commit comments