Skip to content

Commit 7ed3c25

Browse files
authored
Merge pull request pterodactyl#2545 from wardpieters/develop
fix: duplicate 2FA error messages
2 parents fd3b11e + 1c4ee31 commit 7ed3c25

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

resources/scripts/components/auth/LoginCheckpointContainer.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useState } from 'react';
22
import { Link, RouteComponentProps } from 'react-router-dom';
33
import loginCheckpoint from '@/api/auth/loginCheckpoint';
4-
import { httpErrorToHuman } from '@/api/http';
54
import LoginFormContainer from '@/components/auth/LoginFormContainer';
65
import { ActionCreator } from 'easy-peasy';
76
import { StaticContext } from 'react-router';
@@ -20,8 +19,7 @@ interface Values {
2019
type OwnProps = RouteComponentProps<Record<string, string | undefined>, StaticContext, { token?: string }>
2120

2221
type Props = OwnProps & {
23-
addError: ActionCreator<FlashStore['addError']['payload']>;
24-
clearFlashes: ActionCreator<FlashStore['clearFlashes']['payload']>;
22+
clearAndAddHttpError: ActionCreator<FlashStore['clearAndAddHttpError']['payload']>;
2523
}
2624

2725
const LoginCheckpointContainer = () => {
@@ -79,9 +77,7 @@ const LoginCheckpointContainer = () => {
7977
};
8078

8179
const EnhancedForm = withFormik<Props, Values>({
82-
handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { addError, clearFlashes, location } }) => {
83-
clearFlashes();
84-
80+
handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { clearAndAddHttpError, location } }) => {
8581
loginCheckpoint(location.state?.token || '', code, recoveryCode)
8682
.then(response => {
8783
if (response.complete) {
@@ -95,7 +91,7 @@ const EnhancedForm = withFormik<Props, Values>({
9591
.catch(error => {
9692
console.error(error);
9793
setSubmitting(false);
98-
addError({ message: httpErrorToHuman(error) });
94+
clearAndAddHttpError({ error: error });
9995
});
10096
},
10197

@@ -106,7 +102,7 @@ const EnhancedForm = withFormik<Props, Values>({
106102
})(LoginCheckpointContainer);
107103

108104
export default ({ history, location, ...props }: OwnProps) => {
109-
const { addError, clearFlashes } = useFlash();
105+
const { clearAndAddHttpError } = useFlash();
110106

111107
if (!location.state?.token) {
112108
history.replace('/auth/login');
@@ -115,8 +111,7 @@ export default ({ history, location, ...props }: OwnProps) => {
115111
}
116112

117113
return <EnhancedForm
118-
addError={addError}
119-
clearFlashes={clearFlashes}
114+
clearAndAddHttpError={clearAndAddHttpError}
120115
history={history}
121116
location={location}
122117
{...props}

resources/scripts/components/dashboard/forms/DisableTwoFactorModal.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { object, string } from 'yup';
77
import { Actions, useStoreActions } from 'easy-peasy';
88
import { ApplicationStore } from '@/state';
99
import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor';
10-
import { httpErrorToHuman } from '@/api/http';
1110
import tw from 'twin.macro';
1211
import Button from '@/components/elements/Button';
1312

@@ -16,11 +15,10 @@ interface Values {
1615
}
1716

1817
export default ({ ...props }: RequiredModalProps) => {
19-
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
18+
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
2019
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
2120

2221
const submit = ({ password }: Values, { setSubmitting }: FormikHelpers<Values>) => {
23-
clearFlashes('account:two-factor');
2422
disableAccountTwoFactor(password)
2523
.then(() => {
2624
updateUserData({ useTotp: false });
@@ -29,7 +27,7 @@ export default ({ ...props }: RequiredModalProps) => {
2927
.catch(error => {
3028
console.error(error);
3129

32-
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
30+
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
3331
setSubmitting(false);
3432
});
3533
};

resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import getTwoFactorTokenUrl from '@/api/account/getTwoFactorTokenUrl';
66
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
77
import { Actions, useStoreActions } from 'easy-peasy';
88
import { ApplicationStore } from '@/state';
9-
import { httpErrorToHuman } from '@/api/http';
109
import FlashMessageRender from '@/components/FlashMessageRender';
1110
import Field from '@/components/elements/Field';
1211
import tw from 'twin.macro';
@@ -22,28 +21,26 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
2221
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
2322

2423
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
25-
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
24+
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
2625

2726
useEffect(() => {
28-
clearFlashes('account:two-factor');
2927
getTwoFactorTokenUrl()
3028
.then(setToken)
3129
.catch(error => {
3230
console.error(error);
33-
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
31+
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
3432
});
3533
}, []);
3634

3735
const submit = ({ code }: Values, { setSubmitting }: FormikHelpers<Values>) => {
38-
clearFlashes('account:two-factor');
3936
enableAccountTwoFactor(code)
4037
.then(tokens => {
4138
setRecoveryTokens(tokens);
4239
})
4340
.catch(error => {
4441
console.error(error);
4542

46-
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
43+
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
4744
})
4845
.then(() => setSubmitting(false));
4946
};

0 commit comments

Comments
 (0)