diff --git a/src/components/auth/register-form.tsx b/src/components/auth/register-form.tsx index 2709e83..20efd17 100644 --- a/src/components/auth/register-form.tsx +++ b/src/components/auth/register-form.tsx @@ -54,7 +54,9 @@ export const RegisterForm = ({ // turnstile captcha schema const turnstileEnabled = websiteConfig.features.enableTurnstileCaptcha; - const captchaSchema = turnstileEnabled + const captchaSiteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY; + const captchaConfigured = turnstileEnabled && !!captchaSiteKey; + const captchaSchema = captchaConfigured ? z.string().min(1, 'Please complete the captcha') : z.string().optional(); @@ -87,8 +89,8 @@ export const RegisterForm = ({ }); const onSubmit = async (values: z.infer) => { - // Validate captcha token if turnstile is enabled - if (turnstileEnabled && values.captchaToken) { + // Validate captcha token if turnstile is enabled and site key is available + if (captchaConfigured && values.captchaToken) { const captchaResult = await validateCaptchaAction({ captchaToken: values.captchaToken, }); @@ -229,14 +231,14 @@ export const RegisterForm = ({ - {turnstileEnabled && ( + {captchaConfigured && ( form.setValue('captchaToken', token)} validationError={form.formState.errors.captchaToken?.message} /> )}