Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: login recaptcha #4876

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions resources/scripts/components/auth/LoginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Values {

function LoginContainer() {
const ref = useRef<Reaptcha>(null);
const [token, setToken] = useState('');
const token = useRef('');

const { clearFlashes, clearAndAddHttpError } = useFlash();
const { enabled: recaptchaEnabled, siteKey } = useStoreState(state => state.settings.data!.recaptcha);
Expand All @@ -36,7 +36,7 @@ function LoginContainer() {

// 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) {
if (recaptchaEnabled && !token.current) {
ref.current!.execute().catch(error => {
console.error(error);

Expand All @@ -47,7 +47,7 @@ function LoginContainer() {
return;
}

login({ ...values, recaptchaData: token })
login({ ...values, recaptchaData: token.current })
.then(response => {
if (response.complete) {
// @ts-expect-error this is valid
Expand All @@ -60,7 +60,7 @@ function LoginContainer() {
.catch(error => {
console.error(error);

setToken('');
token.current = '';
if (ref.current) ref.current.reset();

setSubmitting(false);
Expand Down Expand Up @@ -94,12 +94,12 @@ function LoginContainer() {
size={'invisible'}
sitekey={siteKey || '_invalid_key'}
onVerify={response => {
setToken(response);
token.current = response;
submitForm();
}}
onExpire={() => {
setSubmitting(false);
setToken('');
token.current = '';
}}
/>
)}
Expand Down