Skip to content

Commit c2b12cf

Browse files
authored
fix(captcha): use getResponsePromise for Turnstile execute-on-submit flow (#3943)
1 parent 4a9439e commit c2b12cf

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

apps/sim/app/(auth)/signup/signup-form.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ function SignupFormContent({
9999
const [showEmailValidationError, setShowEmailValidationError] = useState(false)
100100
const [formError, setFormError] = useState<string | null>(null)
101101
const turnstileRef = useRef<TurnstileInstance>(null)
102-
const captchaResolveRef = useRef<((token: string) => void) | null>(null)
103-
const captchaRejectRef = useRef<((reason: Error) => void) | null>(null)
104102
const turnstileSiteKey = useMemo(() => getEnv('NEXT_PUBLIC_TURNSTILE_SITE_KEY'), [])
105103
const redirectUrl = useMemo(
106104
() => searchParams.get('redirect') || searchParams.get('callbackUrl') || '',
@@ -258,27 +256,14 @@ function SignupFormContent({
258256
let token: string | undefined
259257
const widget = turnstileRef.current
260258
if (turnstileSiteKey && widget) {
261-
let timeoutId: ReturnType<typeof setTimeout> | undefined
262259
try {
263260
widget.reset()
264-
token = await Promise.race([
265-
new Promise<string>((resolve, reject) => {
266-
captchaResolveRef.current = resolve
267-
captchaRejectRef.current = reject
268-
widget.execute()
269-
}),
270-
new Promise<string>((_, reject) => {
271-
timeoutId = setTimeout(() => reject(new Error('Captcha timed out')), 15_000)
272-
}),
273-
])
261+
widget.execute()
262+
token = await widget.getResponsePromise()
274263
} catch {
275264
setFormError('Captcha verification failed. Please try again.')
276265
setIsLoading(false)
277266
return
278-
} finally {
279-
clearTimeout(timeoutId)
280-
captchaResolveRef.current = null
281-
captchaRejectRef.current = null
282267
}
283268
}
284269

@@ -535,10 +520,7 @@ function SignupFormContent({
535520
<Turnstile
536521
ref={turnstileRef}
537522
siteKey={turnstileSiteKey}
538-
onSuccess={(token) => captchaResolveRef.current?.(token)}
539-
onError={() => captchaRejectRef.current?.(new Error('Captcha verification failed'))}
540-
onExpire={() => captchaRejectRef.current?.(new Error('Captcha token expired'))}
541-
options={{ execution: 'execute' }}
523+
options={{ execution: 'execute', appearance: 'execute' }}
542524
/>
543525
)}
544526

0 commit comments

Comments
 (0)