api: add support for cloudflare turnstile

This commit is contained in:
wukko
2024-08-16 00:10:17 +06:00
parent 384c6deced
commit 4283774c6c
3 changed files with 40 additions and 1 deletions

19
api/src/misc/turnstile.js Normal file
View File

@@ -0,0 +1,19 @@
import { env } from "../config.js";
export const verifyTurnstileToken = async (turnstileResponse, ip) => {
const result = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
secret: env.turnstileSecret,
response: turnstileResponse,
remoteip: ip,
}),
})
.then(r => r.json())
.catch(() => {});
return !!result?.success;
}