Return Turnstile verification details

This commit is contained in:
Calum Muir 2025-12-28 12:33:28 +00:00
parent 3df163b656
commit 20df952aa5

View file

@ -57,11 +57,33 @@ const handlePost: PagesFunction<Env> = async ({ request, env }) => {
);
const verifyResult = (await verifyResponse.json()) as {
success?: boolean;
"error-codes"?: string[];
messages?: string[];
hostname?: string;
action?: string;
cdata?: string;
};
if (!verifyResult.success) {
const details = [
verifyResult["error-codes"]?.length
? `codes=${verifyResult["error-codes"].join(",")}`
: "",
verifyResult.messages?.length
? `messages=${verifyResult.messages.join(",")}`
: "",
verifyResult.hostname ? `hostname=${verifyResult.hostname}` : "",
verifyResult.action ? `action=${verifyResult.action}` : "",
]
.filter(Boolean)
.join(" | ")
.slice(0, 500);
return jsonResponse(
{ ok: false, error: "Turnstile verification failed." },
{
ok: false,
error: "Turnstile verification failed.",
details: details || undefined,
},
400,
);
}