feat(api): add captcha verify utility
This commit is contained in:
parent
972e8fa646
commit
09187fa5ac
21
lib/server/middlewareButNotReally/captcha.ts
Normal file
21
lib/server/middlewareButNotReally/captcha.ts
Normal 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",
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user