fix: reset Cloudflare Turnstile token on signup errors (#24927)
* fix: cloudflare turnstile token reset * fix: silently reset turnstile on invalid token error * refactor: remove unused forwardRef logic from Turnstile component - Remove forwardRef, useImperativeHandle, and useRef imports - Remove unused TurnstileInstance type export - Simplify to a plain function component - The ref-based reset was replaced by key-based remount in signup-view * refactor: remove redundant cfToken validation check The submit button is already disabled when cfToken is missing, making this defensive check unreachable during normal form flow. * revert prettier formatiing * chore: revert yarn.lock changes * refactor(auth): use shared constant for cloudflare token error message Replace hardcoded "Invalid cloudflare token" string with an exported constant to prevent silent breakage if the error message changes.
This commit is contained in:
1 parent
7d5e9a4e0e
commit
b220420630
2 files changed
+20
-7
No files matched your search
@@ -2,6 +2,8 @@ import { HttpError } from "../http-error";
|
||||
|
||||
const TURNSTILE_SECRET_ID = process.env.CLOUDFLARE_TURNSTILE_SECRET;
|
||||
|
||||
export const INVALID_CLOUDFLARE_TOKEN_ERROR = "Invalid cloudflare token";
|
||||
|
||||
export async function checkCfTurnstileToken({ token, remoteIp }: { token?: string; remoteIp: string }) {
|
||||
// This means the instance doesn't have turnstile enabled - we skip the check and just return success.
|
||||
// OR the instance is running in CI so we skip these checks also
|
||||
@@ -28,7 +30,7 @@ export async function checkCfTurnstileToken({ token, remoteIp }: { token?: strin
|
||||
const data = await result.json();
|
||||
|
||||
if (!data["success"]) {
|
||||
throw new HttpError({ statusCode: 401, message: "Invalid cloudflare token" });
|
||||
throw new HttpError({ statusCode: 401, message: INVALID_CLOUDFLARE_TOKEN_ERROR });
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
Reference in new issue
Block a user