Skip to content

Commit

Permalink
chore: throw if recaptcha secret is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 26, 2024
1 parent c51e2a4 commit a6cc2b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/src/utils/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ type CaptchaData = {
"error-codes"?: string[];
};

const recaptchaSecret = process.env["RECAPTCHA_SECRET"] ?? null;

export async function verify(captcha: string): Promise<boolean> {
if (isDevEnvironment()) {
return true;
}

if (recaptchaSecret === null) {
throw new Error("RECAPTCHA_SECRET is not defined");
}

const response = 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"]}&response=${captcha}`,
body: `secret=${recaptchaSecret}&response=${captcha}`,
}
);

Expand Down

0 comments on commit a6cc2b5

Please sign in to comment.