Files
thermcool/lib/recaptcha.ts
T

10 lines
492 B
TypeScript

export async function verifyRecaptcha(token: string): Promise<{ success: boolean; score?: number }> {
const res = await fetch('https://www.google.com/recaptcha/api/siteverify', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `secret=${process.env.RECAPTCHA_SECRET_KEY}&response=${token}`,
});
const data = await res.json();
return { success: data.success && (data.score === undefined || data.score >= 0.5), score: data.score };
}