MCPcopy Create free account
hub / github.com/monkeytypegame/monkeytype / verify

Function verify

backend/src/utils/captcha.ts:12–36  ·  view source on GitHub ↗
(captcha: string)

Source from the content-addressed store, hash-verified

10const recaptchaSecret = process.env["RECAPTCHA_SECRET"] ?? null;
11
12export async function verify(captcha: string): Promise<boolean> {
13 if (isDevEnvironment()) {
14 return true;
15 }
16
17 if (recaptchaSecret === null) {
18 throw new Error("RECAPTCHA_SECRET is not defined");
19 }
20
21 const response = await fetch(
22 `https://www.google.com/recaptcha/api/siteverify`,
23 {
24 method: "POST",
25 headers: { "Content-Type": "application/x-www-form-urlencoded" },
26 body: `secret=${recaptchaSecret}&response=${captcha}`,
27 },
28 );
29
30 if (!response.ok) {
31 return false;
32 } else {
33 const captchaData = (await response.json()) as CaptchaData;
34 return captchaData.success;
35 }
36}

Callers 2

verifyCaptchaFunction · 0.90
verifyCaptchaFunction · 0.90

Calls 1

isDevEnvironmentFunction · 0.90

Tested by

no test coverage detected