Skip to content

Commit

Permalink
fix(hCaptcha): provide hCaptcha payload as query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Cali93 committed Jun 7, 2023
1 parent a4aa214 commit d1734e8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/middlewares/captchaVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ export const captchaVerification = async (
}

try {
const hCaptchaResponse = await fetch("https://hcaptcha.com/siteverify", {
method: "POST",
body: JSON.stringify({
response: req.headers["captcha-token"],
secret: process.env.HCAPTCHA_SECRET,
}),
});
const hCaptchaRawResponse = await fetch(
`https://hcaptcha.com/siteverify?secret=${captchaSecret}&response=${captchaToken}`,
{
method: "POST",
}
);
const hCaptchaResponse = (await hCaptchaRawResponse.json()) as {
success: boolean;
challenge_ts: string;
hostname: string;
};

const { success } = (await hCaptchaResponse.json()) as { success: boolean };

if (!success) {
if (!hCaptchaResponse?.success) {
return res.status(403).json({ error: "hCaptcha verification failed" });
}
next();
Expand Down

0 comments on commit d1734e8

Please sign in to comment.