Skip to content

Commit 527ba1a

Browse files
committed
Fix recaptcha not resetting on login fail; closes pterodactyl#2397
1 parent 9621f92 commit 527ba1a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

resources/scripts/components/auth/ForgotPasswordContainer.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ export default () => {
3030
// If there is no token in the state yet, request the token and then abort this submit request
3131
// since it will be re-submitted when the recaptcha data is returned by the component.
3232
if (recaptchaEnabled && !token) {
33-
ref.current!.execute().catch(error => console.error(error));
33+
ref.current!.execute().catch(error => {
34+
console.error(error);
35+
36+
setSubmitting(false);
37+
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
38+
});
39+
3440
return;
3541
}
3642

@@ -43,7 +49,12 @@ export default () => {
4349
console.error(error);
4450
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
4551
})
46-
.then(() => setSubmitting(false));
52+
.then(() => {
53+
setToken('');
54+
if (ref.current) ref.current.reset();
55+
56+
setSubmitting(false);
57+
});
4758
};
4859

4960
return (

resources/scripts/components/auth/LoginContainer.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
2929
// If there is no token in the state yet, request the token and then abort this submit request
3030
// since it will be re-submitted when the recaptcha data is returned by the component.
3131
if (recaptchaEnabled && !token) {
32-
ref.current!.execute().catch(error => console.error(error));
32+
ref.current!.execute().catch(error => {
33+
console.error(error);
34+
35+
setSubmitting(false);
36+
clearAndAddHttpError({ error });
37+
});
38+
3339
return;
3440
}
3541

@@ -46,6 +52,9 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
4652
.catch(error => {
4753
console.error(error);
4854

55+
setToken('');
56+
if (ref.current) ref.current.reset();
57+
4958
setSubmitting(false);
5059
clearAndAddHttpError({ error });
5160
});
@@ -63,23 +72,23 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
6372
{({ isSubmitting, setSubmitting, submitForm }) => (
6473
<LoginFormContainer title={'Login to Continue'} css={tw`w-full flex`}>
6574
<Field
75+
light
6676
type={'text'}
6777
label={'Username or Email'}
68-
id={'username'}
6978
name={'username'}
70-
light
79+
disabled={isSubmitting}
7180
/>
7281
<div css={tw`mt-6`}>
7382
<Field
83+
light
7484
type={'password'}
7585
label={'Password'}
76-
id={'password'}
7786
name={'password'}
78-
light
87+
disabled={isSubmitting}
7988
/>
8089
</div>
8190
<div css={tw`mt-6`}>
82-
<Button type={'submit'} size={'xlarge'} isLoading={isSubmitting}>
91+
<Button type={'submit'} size={'xlarge'} isLoading={isSubmitting} disabled={isSubmitting}>
8392
Login
8493
</Button>
8594
</div>

0 commit comments

Comments
 (0)