diff --git a/backend/src/utils/captcha.ts b/backend/src/utils/captcha.ts index 31e8cdb1d9b4..7c95a2f304dd 100644 --- a/backend/src/utils/captcha.ts +++ b/backend/src/utils/captcha.ts @@ -8,16 +8,23 @@ type CaptchaData = { "error-codes"?: string[]; }; +const recaptchaSecret = process.env["RECAPTCHA_SECRET"] ?? null; + export async function verify(captcha: string): Promise { 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}`, } );