PronounsPage/server/captcha.js
2021-08-07 12:03:49 +02:00

14 lines
452 B
JavaScript

import fetch from 'node-fetch';
export const validateCaptcha = async (token) => {
const res = await fetch('https://hcaptcha.com/siteverify', {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
body: `response=${encodeURIComponent(token)}&secret=${encodeURIComponent(process.env.HCAPTCHA_SECRET)}`
});
const body = await res.json();
return body['success'];
}