mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-02 12:00:10 +08:00
7ef0c424d6
* Migrate some utils to TS * Add argument type * Fix logic * Refactor math functions * Rename function
24 lines
642 B
TypeScript
24 lines
642 B
TypeScript
import fetch from "node-fetch";
|
|
|
|
interface CaptchaData {
|
|
success: boolean;
|
|
challenge_ts?: number;
|
|
hostname: string;
|
|
"error-codes"?: string[];
|
|
}
|
|
|
|
export async function verify(captcha: string): Promise<boolean> {
|
|
if (process.env.MODE === "dev") {
|
|
return true;
|
|
}
|
|
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}`,
|
|
}
|
|
);
|
|
const captchaData = (await response.json()) as CaptchaData;
|
|
return captchaData.success;
|
|
}
|