feat: add ReCaptchaV2 & Turnstile

This commit is contained in:
Tony Yang
2025-04-16 16:35:24 +08:00
parent 9ac3339557
commit 037ccb5781
23 changed files with 372 additions and 176 deletions
+2 -11
View File
@@ -1,6 +1,6 @@
import { verifyJWT } from '../middleware/auth';
import { captchaPlugins } from '../middleware/captcha';
import { createErrorResponse, createSuccessResponse } from '../utils';
import hCaptchaPlugin from "@cloudflare/pages-plugin-hcaptcha";
export async function onRequestGet(context) {
try {
@@ -17,16 +17,7 @@ export async function onRequestGet(context) {
}
export const onRequestPost = [
async (context) => {
return hCaptchaPlugin({
secret: context.env.hcaptcha_secret_key,
sitekey: context.env.hcaptcha_site_key,
onError: (context) => {
console.error("hCaptcha error:", context.error);
return createErrorResponse("hCaptcha verification failed", 403);
}
})(context);
},
...captchaPlugins,
async (context) => {
try {
const { request, env } = context;