PronounsPage/server/captcha.ts
Valentyne Stigloher 7ce1bb0e83 (ts) convert a lot to TypeScript
Co-authored-by: Sky <msurvival65@gmail.com>
Co-authored-by: tecc <tecc@tecc.me>
2024-02-23 17:48:16 +01:00

14 lines
505 B
TypeScript

import fetch from 'node-fetch';
export const validateCaptcha = async (token: string): Promise<boolean> => {
const res = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
body: `response=${encodeURIComponent(token)}&secret=${encodeURIComponent(process.env.TURNSTILE_SECRET!)}`,
});
const body = await res.json();
return body.success;
};