From 5216d6a543be33b1b17c79ff217de82610b107a8 Mon Sep 17 00:00:00 2001 From: waleed Date: Sat, 4 Apr 2026 12:25:21 -0700 Subject: [PATCH] fix(captcha): use getResponsePromise for Turnstile execute-on-submit flow --- apps/sim/app/(auth)/signup/signup-form.tsx | 24 +++------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/apps/sim/app/(auth)/signup/signup-form.tsx b/apps/sim/app/(auth)/signup/signup-form.tsx index 7ddf2abbcaa..1b0bd50c05b 100644 --- a/apps/sim/app/(auth)/signup/signup-form.tsx +++ b/apps/sim/app/(auth)/signup/signup-form.tsx @@ -99,8 +99,6 @@ function SignupFormContent({ const [showEmailValidationError, setShowEmailValidationError] = useState(false) const [formError, setFormError] = useState(null) const turnstileRef = useRef(null) - const captchaResolveRef = useRef<((token: string) => void) | null>(null) - const captchaRejectRef = useRef<((reason: Error) => void) | null>(null) const turnstileSiteKey = useMemo(() => getEnv('NEXT_PUBLIC_TURNSTILE_SITE_KEY'), []) const redirectUrl = useMemo( () => searchParams.get('redirect') || searchParams.get('callbackUrl') || '', @@ -258,27 +256,14 @@ function SignupFormContent({ let token: string | undefined const widget = turnstileRef.current if (turnstileSiteKey && widget) { - let timeoutId: ReturnType | undefined try { widget.reset() - token = await Promise.race([ - new Promise((resolve, reject) => { - captchaResolveRef.current = resolve - captchaRejectRef.current = reject - widget.execute() - }), - new Promise((_, reject) => { - timeoutId = setTimeout(() => reject(new Error('Captcha timed out')), 15_000) - }), - ]) + widget.execute() + token = await widget.getResponsePromise() } catch { setFormError('Captcha verification failed. Please try again.') setIsLoading(false) return - } finally { - clearTimeout(timeoutId) - captchaResolveRef.current = null - captchaRejectRef.current = null } } @@ -535,10 +520,7 @@ function SignupFormContent({ captchaResolveRef.current?.(token)} - onError={() => captchaRejectRef.current?.(new Error('Captcha verification failed'))} - onExpire={() => captchaRejectRef.current?.(new Error('Captcha token expired'))} - options={{ execution: 'execute' }} + options={{ execution: 'execute', appearance: 'execute' }} /> )}