diff --git a/lib/server/middlewareButNotReally/captcha.ts b/lib/server/middlewareButNotReally/captcha.ts new file mode 100644 index 0000000..3c164c7 --- /dev/null +++ b/lib/server/middlewareButNotReally/captcha.ts @@ -0,0 +1,21 @@ +import { H3Event, EventHandlerRequest } from "h3"; +export default async function (ev: H3Event) { + const body = await readBody(ev); + + let { data: cres }: { data: any } = await useFetch( + "https://www.google.com/recaptcha/api/siteverify", + { + method: "post", + body: { + secret: useRuntimeConfig().captcha.secret, + response: body["g-recaptcha-response"], + }, + }, + ); + if (!cres.value.success) { + throw createError({ + statusCode: 400, + message: "bad recaptcha", + }); + } +}