Fix recaptcha not resetting on login fail; closes #2397

This commit is contained in:
Dane Everitt 2020-10-17 14:30:54 -07:00
parent 9621f923f5
commit 527ba1adc4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 28 additions and 8 deletions

View file

@ -30,7 +30,13 @@ export default () => {
// If there is no token in the state yet, request the token and then abort this submit request // If there is no token in the state yet, request the token and then abort this submit request
// since it will be re-submitted when the recaptcha data is returned by the component. // since it will be re-submitted when the recaptcha data is returned by the component.
if (recaptchaEnabled && !token) { if (recaptchaEnabled && !token) {
ref.current!.execute().catch(error => console.error(error)); ref.current!.execute().catch(error => {
console.error(error);
setSubmitting(false);
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
});
return; return;
} }
@ -43,7 +49,12 @@ export default () => {
console.error(error); console.error(error);
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) }); addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
}) })
.then(() => setSubmitting(false)); .then(() => {
setToken('');
if (ref.current) ref.current.reset();
setSubmitting(false);
});
}; };
return ( return (

View file

@ -29,7 +29,13 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
// If there is no token in the state yet, request the token and then abort this submit request // If there is no token in the state yet, request the token and then abort this submit request
// since it will be re-submitted when the recaptcha data is returned by the component. // since it will be re-submitted when the recaptcha data is returned by the component.
if (recaptchaEnabled && !token) { if (recaptchaEnabled && !token) {
ref.current!.execute().catch(error => console.error(error)); ref.current!.execute().catch(error => {
console.error(error);
setSubmitting(false);
clearAndAddHttpError({ error });
});
return; return;
} }
@ -46,6 +52,9 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
.catch(error => { .catch(error => {
console.error(error); console.error(error);
setToken('');
if (ref.current) ref.current.reset();
setSubmitting(false); setSubmitting(false);
clearAndAddHttpError({ error }); clearAndAddHttpError({ error });
}); });
@ -63,23 +72,23 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
{({ isSubmitting, setSubmitting, submitForm }) => ( {({ isSubmitting, setSubmitting, submitForm }) => (
<LoginFormContainer title={'Login to Continue'} css={tw`w-full flex`}> <LoginFormContainer title={'Login to Continue'} css={tw`w-full flex`}>
<Field <Field
light
type={'text'} type={'text'}
label={'Username or Email'} label={'Username or Email'}
id={'username'}
name={'username'} name={'username'}
light disabled={isSubmitting}
/> />
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Field <Field
light
type={'password'} type={'password'}
label={'Password'} label={'Password'}
id={'password'}
name={'password'} name={'password'}
light disabled={isSubmitting}
/> />
</div> </div>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Button type={'submit'} size={'xlarge'} isLoading={isSubmitting}> <Button type={'submit'} size={'xlarge'} isLoading={isSubmitting} disabled={isSubmitting}>
Login Login
</Button> </Button>
</div> </div>