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",
		});
	}
}
