(captcha: string)
| 10 | const recaptchaSecret = process.env["RECAPTCHA_SECRET"] ?? null; |
| 11 | |
| 12 | export 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 | } |
no test coverage detected