Commit 7e462f71 authored by tom's avatar tom

generalize solution of recaptcha reset

parent 07388c62
...@@ -8,6 +8,12 @@ interface Props { ...@@ -8,6 +8,12 @@ interface Props {
} }
const ReCaptchaInvisible = ({ disabledFeatureMessage }: Props, ref: React.Ref<ReCaptcha>) => { const ReCaptchaInvisible = ({ disabledFeatureMessage }: Props, ref: React.Ref<ReCaptcha>) => {
const [ attempt, setAttempt ] = React.useState(0);
const handleChange = React.useCallback(() => {
setAttempt(attempt + 1);
}, [ attempt ]);
if (!config.services.reCaptchaV2.siteKey) { if (!config.services.reCaptchaV2.siteKey) {
return disabledFeatureMessage ?? null; return disabledFeatureMessage ?? null;
} }
...@@ -15,8 +21,10 @@ const ReCaptchaInvisible = ({ disabledFeatureMessage }: Props, ref: React.Ref<Re ...@@ -15,8 +21,10 @@ const ReCaptchaInvisible = ({ disabledFeatureMessage }: Props, ref: React.Ref<Re
return ( return (
<ReCaptcha <ReCaptcha
ref={ ref } ref={ ref }
key={ attempt }
sitekey={ config.services.reCaptchaV2.siteKey } sitekey={ config.services.reCaptchaV2.siteKey }
size="invisible" size="invisible"
onChange={ handleChange }
/> />
); );
}; };
......
...@@ -28,7 +28,6 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => { ...@@ -28,7 +28,6 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => {
const toast = useToast(); const toast = useToast();
const recaptcha = useReCaptcha(); const recaptcha = useReCaptcha();
const [ isCodeSending, setIsCodeSending ] = React.useState(false); const [ isCodeSending, setIsCodeSending ] = React.useState(false);
const [ resendAttempts, setResendAttempts ] = React.useState(0);
const formApi = useForm<OtpCodeFormFields>({ const formApi = useForm<OtpCodeFormFields>({
mode: 'onBlur', mode: 'onBlur',
...@@ -96,7 +95,6 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => { ...@@ -96,7 +95,6 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => {
description: apiError?.message || getErrorMessage(error) || 'Something went wrong', description: apiError?.message || getErrorMessage(error) || 'Something went wrong',
}); });
} finally { } finally {
setResendAttempts((prev) => prev + 1);
setIsCodeSending(false); setIsCodeSending(false);
} }
}, [ apiFetch, email, formApi, toast, recaptcha ]); }, [ apiFetch, email, formApi, toast, recaptcha ]);
...@@ -113,7 +111,7 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => { ...@@ -113,7 +111,7 @@ const AuthModalScreenOtpCode = ({ email, onSuccess, isAuth }: Props) => {
and enter your code below. and enter your code below.
</Text> </Text>
<AuthModalFieldOtpCode isDisabled={ isCodeSending }/> <AuthModalFieldOtpCode isDisabled={ isCodeSending }/>
<ReCaptcha key={ resendAttempts } ref={ recaptcha.ref }/> <ReCaptcha ref={ recaptcha.ref }/>
<Button <Button
variant="link" variant="link"
display="flex" display="flex"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment