Return Turnstile verification details
This commit is contained in:
parent
3df163b656
commit
20df952aa5
1 changed files with 23 additions and 1 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue