From fbc9a6f4c73053ac238065f140818dd06e658bb1 Mon Sep 17 00:00:00 2001 From: rique223 Date: Fri, 2 Feb 2024 18:50:58 -0300 Subject: [PATCH] fix: :bug: GUI crash when 2fa is canceled/closed Fixed a bug in which the LoginForm would crash upon the cancellation or closure of the 2FA modal. This issue occurred because the "totp-canceled" error was not mapped to the list of errors that could occur with this component. --- .../TwoFactorModal/TwoFactorEmailModal.tsx | 16 +++------------- packages/web-ui-registration/src/LoginForm.tsx | 7 ++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx index 5b2a83ed8cea..19074f7f6b34 100644 --- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx +++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx @@ -45,24 +45,14 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem }; const id = useUniqueId(); - const onCloseHandler = () => { - try { - if (typeof onClose === 'function') { - onClose(); - window.location.href = 'http://localhost:3000'; - } - } catch (error) { - console.error('Error in onClose function:', error); - } - }; return ( } - onCancel={onCloseHandler} + onCancel={onClose} confirmText={t('Verify')} title={t('Two-factor_authentication_email')} - onClose={onCloseHandler} + onClose={onClose} variant='warning' icon='info' confirmDisabled={!code} @@ -78,7 +68,7 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem {invalidAttempt && {t('Invalid_password')}} - + {t('Cloud_resend_email')} diff --git a/packages/web-ui-registration/src/LoginForm.tsx b/packages/web-ui-registration/src/LoginForm.tsx index 55c638df6707..3290b9f16191 100644 --- a/packages/web-ui-registration/src/LoginForm.tsx +++ b/packages/web-ui-registration/src/LoginForm.tsx @@ -56,7 +56,7 @@ const LOGIN_SUBMIT_ERRORS = { }, } as const; -export type LoginErrors = keyof typeof LOGIN_SUBMIT_ERRORS; +export type LoginErrors = keyof typeof LOGIN_SUBMIT_ERRORS | 'totp-canceled'; export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRouter }): ReactElement => { const { @@ -111,7 +111,12 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute }, [errorOnSubmit]); const renderErrorOnSubmit = (error: LoginErrors) => { + if (error === 'totp-canceled') { + return null; + } + const { type, i18n } = LOGIN_SUBMIT_ERRORS[error]; + return ( {t(i18n)}