From f859d37b251d4434c26f52700ca1420d91dd5788 Mon Sep 17 00:00:00 2001 From: Ward Pieters Date: Sun, 18 Oct 2020 00:02:46 +0200 Subject: [PATCH 1/3] fix: duplicate 2FA error messages (https://github.com/pterodactyl/panel/issues/2455) --- .../components/auth/LoginCheckpointContainer.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/resources/scripts/components/auth/LoginCheckpointContainer.tsx b/resources/scripts/components/auth/LoginCheckpointContainer.tsx index f45073281..4c3dff599 100644 --- a/resources/scripts/components/auth/LoginCheckpointContainer.tsx +++ b/resources/scripts/components/auth/LoginCheckpointContainer.tsx @@ -1,7 +1,6 @@ import React, { useState } from 'react'; import { Link, RouteComponentProps } from 'react-router-dom'; import loginCheckpoint from '@/api/auth/loginCheckpoint'; -import { httpErrorToHuman } from '@/api/http'; import LoginFormContainer from '@/components/auth/LoginFormContainer'; import { ActionCreator } from 'easy-peasy'; import { StaticContext } from 'react-router'; @@ -20,8 +19,7 @@ interface Values { type OwnProps = RouteComponentProps, StaticContext, { token?: string }> type Props = OwnProps & { - addError: ActionCreator; - clearFlashes: ActionCreator; + clearAndAddHttpError: ActionCreator; } const LoginCheckpointContainer = () => { @@ -79,9 +77,7 @@ const LoginCheckpointContainer = () => { }; const EnhancedForm = withFormik({ - handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { addError, clearFlashes, location } }) => { - clearFlashes(); - + handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { clearAndAddHttpError, location } }) => { loginCheckpoint(location.state?.token || '', code, recoveryCode) .then(response => { if (response.complete) { @@ -95,7 +91,7 @@ const EnhancedForm = withFormik({ .catch(error => { console.error(error); setSubmitting(false); - addError({ message: httpErrorToHuman(error) }); + clearAndAddHttpError({ error: error }); }); }, @@ -106,7 +102,7 @@ const EnhancedForm = withFormik({ })(LoginCheckpointContainer); export default ({ history, location, ...props }: OwnProps) => { - const { addError, clearFlashes } = useFlash(); + const { clearAndAddHttpError } = useFlash(); if (!location.state?.token) { history.replace('/auth/login'); @@ -115,8 +111,7 @@ export default ({ history, location, ...props }: OwnProps) => { } return Date: Sun, 18 Oct 2020 00:42:52 +0200 Subject: [PATCH 2/3] fix: duplicate disable 2FA error messages --- .../components/dashboard/forms/DisableTwoFactorModal.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/scripts/components/dashboard/forms/DisableTwoFactorModal.tsx b/resources/scripts/components/dashboard/forms/DisableTwoFactorModal.tsx index 170cd01d3..d4f986942 100644 --- a/resources/scripts/components/dashboard/forms/DisableTwoFactorModal.tsx +++ b/resources/scripts/components/dashboard/forms/DisableTwoFactorModal.tsx @@ -7,7 +7,6 @@ import { object, string } from 'yup'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor'; -import { httpErrorToHuman } from '@/api/http'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; @@ -16,11 +15,10 @@ interface Values { } export default ({ ...props }: RequiredModalProps) => { - const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); + const { clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData); const submit = ({ password }: Values, { setSubmitting }: FormikHelpers) => { - clearFlashes('account:two-factor'); disableAccountTwoFactor(password) .then(() => { updateUserData({ useTotp: false }); @@ -29,7 +27,7 @@ export default ({ ...props }: RequiredModalProps) => { .catch(error => { console.error(error); - addError({ message: httpErrorToHuman(error), key: 'account:two-factor' }); + clearAndAddHttpError({ error: error, key: 'account:two-factor' }); setSubmitting(false); }); }; From 1c4ee31491212ada682a4caed01c67edfc8ac945 Mon Sep 17 00:00:00 2001 From: Ward Pieters Date: Sun, 18 Oct 2020 00:46:46 +0200 Subject: [PATCH 3/3] fix: duplicate enable 2FA error messages --- .../components/dashboard/forms/SetupTwoFactorModal.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx b/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx index 619067486..eb8e1a890 100644 --- a/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx +++ b/resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx @@ -6,7 +6,6 @@ import getTwoFactorTokenUrl from '@/api/account/getTwoFactorTokenUrl'; import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; -import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; import Field from '@/components/elements/Field'; import tw from 'twin.macro'; @@ -22,20 +21,18 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => { const [ recoveryTokens, setRecoveryTokens ] = useState([]); const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData); - const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); + const { clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); useEffect(() => { - clearFlashes('account:two-factor'); getTwoFactorTokenUrl() .then(setToken) .catch(error => { console.error(error); - addError({ message: httpErrorToHuman(error), key: 'account:two-factor' }); + clearAndAddHttpError({ error: error, key: 'account:two-factor' }); }); }, []); const submit = ({ code }: Values, { setSubmitting }: FormikHelpers) => { - clearFlashes('account:two-factor'); enableAccountTwoFactor(code) .then(tokens => { setRecoveryTokens(tokens); @@ -43,7 +40,7 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => { .catch(error => { console.error(error); - addError({ message: httpErrorToHuman(error), key: 'account:two-factor' }); + clearAndAddHttpError({ error: error, key: 'account:two-factor' }); }) .then(() => setSubmitting(false)); };