mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 18:27:33 +08:00
chore: throw if recaptcha secret is undefined
This commit is contained in:
parent
c51e2a47e4
commit
a6cc2b5eff
1 changed files with 8 additions and 1 deletions
|
|
@ -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}`,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue