Skip to content

Commit 7b8f2d0

Browse files
waleedlatif1claude
andcommitted
fix(auth): clear dangling timeout after captcha promise settles
Use .finally(() => clearTimeout(timeoutId)) to clean up the 15s timeout timer when the captcha resolves before the deadline. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9ceb30d commit 7b8f2d0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,17 @@ export default function LoginPage({
176176
if (turnstileSiteKey && turnstileRef.current) {
177177
try {
178178
turnstileRef.current.reset()
179+
let timeoutId: ReturnType<typeof setTimeout> | undefined
179180
token = await Promise.race([
180181
new Promise<string>((resolve, reject) => {
181182
captchaResolveRef.current = resolve
182183
captchaRejectRef.current = reject
183184
turnstileRef.current?.execute()
184185
}),
185-
new Promise<string>((_, reject) =>
186-
setTimeout(() => reject(new Error('Captcha timed out')), 15_000)
187-
),
188-
])
186+
new Promise<string>((_, reject) => {
187+
timeoutId = setTimeout(() => reject(new Error('Captcha timed out')), 15_000)
188+
}),
189+
]).finally(() => clearTimeout(timeoutId))
189190
} catch {
190191
setPasswordErrors(['Captcha verification failed. Please try again.'])
191192
setShowValidationError(true)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,17 @@ function SignupFormContent({
256256
if (turnstileSiteKey && turnstileRef.current) {
257257
try {
258258
turnstileRef.current.reset()
259+
let timeoutId: ReturnType<typeof setTimeout> | undefined
259260
token = await Promise.race([
260261
new Promise<string>((resolve, reject) => {
261262
captchaResolveRef.current = resolve
262263
captchaRejectRef.current = reject
263264
turnstileRef.current?.execute()
264265
}),
265-
new Promise<string>((_, reject) =>
266-
setTimeout(() => reject(new Error('Captcha timed out')), 15_000)
267-
),
268-
])
266+
new Promise<string>((_, reject) => {
267+
timeoutId = setTimeout(() => reject(new Error('Captcha timed out')), 15_000)
268+
}),
269+
]).finally(() => clearTimeout(timeoutId))
269270
} catch {
270271
setPasswordErrors(['Captcha verification failed. Please try again.'])
271272
setShowValidationError(true)

0 commit comments

Comments
 (0)