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
// since it will be re-submitted when the recaptcha data is returned by the component.
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;
}
@ -43,7 +49,12 @@ export default () => {
console.error(error);
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
})
.then(() => setSubmitting(false));
.then(() => {
setToken('');
if (ref.current) ref.current.reset();
setSubmitting(false);
});
};
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
// since it will be re-submitted when the recaptcha data is returned by the component.
if (recaptchaEnabled && !token) {
ref.current!.execute().catch(error => console.error(error));
ref.current!.execute().catch(error => {
console.error(error);
setSubmitting(false);
clearAndAddHttpError({ error });
});
return;
}
@ -46,6 +52,9 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
.catch(error => {
console.error(error);
setToken('');
if (ref.current) ref.current.reset();
setSubmitting(false);
clearAndAddHttpError({ error });
});
@ -63,23 +72,23 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
{({ isSubmitting, setSubmitting, submitForm }) => (
<LoginFormContainer title={'Login to Continue'} css={tw`w-full flex`}>
<Field
light
type={'text'}
label={'Username or Email'}
id={'username'}
name={'username'}
light
disabled={isSubmitting}
/>
<div css={tw`mt-6`}>
<Field
light
type={'password'}
label={'Password'}
id={'password'}
name={'password'}
light
disabled={isSubmitting}
/>
</div>
<div css={tw`mt-6`}>
<Button type={'submit'} size={'xlarge'} isLoading={isSubmitting}>
<Button type={'submit'} size={'xlarge'} isLoading={isSubmitting} disabled={isSubmitting}>
Login
</Button>
</div>