feat(api): add captcha verify utility

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-03 00:26:51 -04:00
parent 972e8fa646
commit 09187fa5ac
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -0,0 +1,21 @@
import { H3Event, EventHandlerRequest } from "h3";
export default async function (ev: H3Event<EventHandlerRequest>) {
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",
});
}
}