Fix captcha: resetear Turnstile tras un fallo (token de un solo uso)

Al fallar (p.ej. contraseña incorrecta) el token de Turnstile ya se consumió en el
servidor; el reintento reenviaba el mismo token y daba "captcha fallida" aunque
estuviera resuelto. Se resetea el widget (setCaptcha('') + captchaKey++ con
<Turnstile key={captchaKey}>, mismo patrón que recover/restore/quest) en login,
create-account y trade-points (venta y canje). El check de código no usa captcha,
no se resetea ahí.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-14 21:17:37 +00:00
parent 20e1d5a6b5
commit 942fe2e397
3 changed files with 27 additions and 4 deletions
@@ -62,6 +62,7 @@ export function RegisterForm() {
const [notUs, setNotUs] = useState(false)
const [busy, setBusy] = useState(false)
const [captcha, setCaptcha] = useState('')
const [captchaKey, setCaptchaKey] = useState(0) // remonta el widget para pedir un token nuevo
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null)
const canSubmit = accepted && notUs && !busy
@@ -102,9 +103,14 @@ export function RegisterForm() {
} else {
const key = (ERROR_KEYS as readonly string[]).includes(data.error ?? '') ? data.error! : 'genericError'
setMessage({ ok: false, text: t(key) })
// El token de Turnstile es de un solo uso: resetear tras un fallo.
setCaptcha('')
setCaptchaKey((k) => k + 1)
}
} catch {
setMessage({ ok: false, text: t('genericError') })
setCaptcha('')
setCaptchaKey((k) => k + 1)
} finally {
setBusy(false)
}
@@ -162,7 +168,7 @@ export function RegisterForm() {
</tr>
<tr>
<td>
<Turnstile onVerify={setCaptcha} />
<Turnstile key={captchaKey} onVerify={setCaptcha} />
</td>
</tr>
<tr>
+8 -1
View File
@@ -14,6 +14,7 @@ export function LoginForm() {
const [showPw, setShowPw] = useState(false)
const [busy, setBusy] = useState(false)
const [captcha, setCaptcha] = useState('')
const [captchaKey, setCaptchaKey] = useState(0) // remonta el widget para pedir un token nuevo
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null)
async function handleSubmit(e: React.FormEvent) {
@@ -43,10 +44,16 @@ export function LoginForm() {
} else {
const key = (ERROR_KEYS as readonly string[]).includes(data.error ?? '') ? data.error! : 'genericError'
setMessage({ ok: false, text: t(key) })
// El token de Turnstile es de un solo uso: tras un fallo hay que resetear
// el widget para emitir uno nuevo, o el reintento daría "captcha ya usado".
setCaptcha('')
setCaptchaKey((k) => k + 1)
setBusy(false)
}
} catch {
setMessage({ ok: false, text: t('genericError') })
setCaptcha('')
setCaptchaKey((k) => k + 1)
setBusy(false)
}
}
@@ -93,7 +100,7 @@ export function LoginForm() {
</tr>
<tr>
<td>
<Turnstile onVerify={setCaptcha} />
<Turnstile key={captchaKey} onVerify={setCaptcha} />
</td>
</tr>
<tr>