Merge pull request #2545 from wardpieters/develop
fix: duplicate 2FA error messages
This commit is contained in:
commit
7ed3c25d61
3 changed files with 10 additions and 20 deletions
|
@ -1,7 +1,6 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Link, RouteComponentProps } from 'react-router-dom';
|
import { Link, RouteComponentProps } from 'react-router-dom';
|
||||||
import loginCheckpoint from '@/api/auth/loginCheckpoint';
|
import loginCheckpoint from '@/api/auth/loginCheckpoint';
|
||||||
import { httpErrorToHuman } from '@/api/http';
|
|
||||||
import LoginFormContainer from '@/components/auth/LoginFormContainer';
|
import LoginFormContainer from '@/components/auth/LoginFormContainer';
|
||||||
import { ActionCreator } from 'easy-peasy';
|
import { ActionCreator } from 'easy-peasy';
|
||||||
import { StaticContext } from 'react-router';
|
import { StaticContext } from 'react-router';
|
||||||
|
@ -20,8 +19,7 @@ interface Values {
|
||||||
type OwnProps = RouteComponentProps<Record<string, string | undefined>, StaticContext, { token?: string }>
|
type OwnProps = RouteComponentProps<Record<string, string | undefined>, StaticContext, { token?: string }>
|
||||||
|
|
||||||
type Props = OwnProps & {
|
type Props = OwnProps & {
|
||||||
addError: ActionCreator<FlashStore['addError']['payload']>;
|
clearAndAddHttpError: ActionCreator<FlashStore['clearAndAddHttpError']['payload']>;
|
||||||
clearFlashes: ActionCreator<FlashStore['clearFlashes']['payload']>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const LoginCheckpointContainer = () => {
|
const LoginCheckpointContainer = () => {
|
||||||
|
@ -79,9 +77,7 @@ const LoginCheckpointContainer = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const EnhancedForm = withFormik<Props, Values>({
|
const EnhancedForm = withFormik<Props, Values>({
|
||||||
handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { addError, clearFlashes, location } }) => {
|
handleSubmit: ({ code, recoveryCode }, { setSubmitting, props: { clearAndAddHttpError, location } }) => {
|
||||||
clearFlashes();
|
|
||||||
|
|
||||||
loginCheckpoint(location.state?.token || '', code, recoveryCode)
|
loginCheckpoint(location.state?.token || '', code, recoveryCode)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.complete) {
|
if (response.complete) {
|
||||||
|
@ -95,7 +91,7 @@ const EnhancedForm = withFormik<Props, Values>({
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
addError({ message: httpErrorToHuman(error) });
|
clearAndAddHttpError({ error: error });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -106,7 +102,7 @@ const EnhancedForm = withFormik<Props, Values>({
|
||||||
})(LoginCheckpointContainer);
|
})(LoginCheckpointContainer);
|
||||||
|
|
||||||
export default ({ history, location, ...props }: OwnProps) => {
|
export default ({ history, location, ...props }: OwnProps) => {
|
||||||
const { addError, clearFlashes } = useFlash();
|
const { clearAndAddHttpError } = useFlash();
|
||||||
|
|
||||||
if (!location.state?.token) {
|
if (!location.state?.token) {
|
||||||
history.replace('/auth/login');
|
history.replace('/auth/login');
|
||||||
|
@ -115,8 +111,7 @@ export default ({ history, location, ...props }: OwnProps) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return <EnhancedForm
|
return <EnhancedForm
|
||||||
addError={addError}
|
clearAndAddHttpError={clearAndAddHttpError}
|
||||||
clearFlashes={clearFlashes}
|
|
||||||
history={history}
|
history={history}
|
||||||
location={location}
|
location={location}
|
||||||
{...props}
|
{...props}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import { object, string } from 'yup';
|
||||||
import { Actions, useStoreActions } from 'easy-peasy';
|
import { Actions, useStoreActions } from 'easy-peasy';
|
||||||
import { ApplicationStore } from '@/state';
|
import { ApplicationStore } from '@/state';
|
||||||
import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor';
|
import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor';
|
||||||
import { httpErrorToHuman } from '@/api/http';
|
|
||||||
import tw from 'twin.macro';
|
import tw from 'twin.macro';
|
||||||
import Button from '@/components/elements/Button';
|
import Button from '@/components/elements/Button';
|
||||||
|
|
||||||
|
@ -16,11 +15,10 @@ interface Values {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ ...props }: RequiredModalProps) => {
|
export default ({ ...props }: RequiredModalProps) => {
|
||||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||||
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
||||||
|
|
||||||
const submit = ({ password }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
const submit = ({ password }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||||
clearFlashes('account:two-factor');
|
|
||||||
disableAccountTwoFactor(password)
|
disableAccountTwoFactor(password)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
updateUserData({ useTotp: false });
|
updateUserData({ useTotp: false });
|
||||||
|
@ -29,7 +27,7 @@ export default ({ ...props }: RequiredModalProps) => {
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
|
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,6 @@ import getTwoFactorTokenUrl from '@/api/account/getTwoFactorTokenUrl';
|
||||||
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
|
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
|
||||||
import { Actions, useStoreActions } from 'easy-peasy';
|
import { Actions, useStoreActions } from 'easy-peasy';
|
||||||
import { ApplicationStore } from '@/state';
|
import { ApplicationStore } from '@/state';
|
||||||
import { httpErrorToHuman } from '@/api/http';
|
|
||||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||||
import Field from '@/components/elements/Field';
|
import Field from '@/components/elements/Field';
|
||||||
import tw from 'twin.macro';
|
import tw from 'twin.macro';
|
||||||
|
@ -22,20 +21,18 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
|
||||||
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
|
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
|
||||||
|
|
||||||
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
||||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
clearFlashes('account:two-factor');
|
|
||||||
getTwoFactorTokenUrl()
|
getTwoFactorTokenUrl()
|
||||||
.then(setToken)
|
.then(setToken)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(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<Values>) => {
|
const submit = ({ code }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||||
clearFlashes('account:two-factor');
|
|
||||||
enableAccountTwoFactor(code)
|
enableAccountTwoFactor(code)
|
||||||
.then(tokens => {
|
.then(tokens => {
|
||||||
setRecoveryTokens(tokens);
|
setRecoveryTokens(tokens);
|
||||||
|
@ -43,7 +40,7 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
|
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
|
||||||
})
|
})
|
||||||
.then(() => setSubmitting(false));
|
.then(() => setSubmitting(false));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue