feat(turnstile): integrate Cloudflare Turnstile for enhanced security in login and registration processes

This commit is contained in:
beilunyang
2025-10-22 23:31:48 +08:00
parent 1ffe920d47
commit e431c1fe5b
22 changed files with 480 additions and 56 deletions

View File

@@ -1,6 +1,7 @@
import { NextResponse } from "next/server"
import { register } from "@/lib/auth"
import { authSchema, AuthSchema } from "@/lib/validation"
import { verifyTurnstileToken } from "@/lib/turnstile"
export const runtime = "edge"
@@ -17,7 +18,16 @@ export async function POST(request: Request) {
)
}
const { username, password } = json
const { username, password, turnstileToken } = json
const verification = await verifyTurnstileToken(turnstileToken)
if (!verification.success) {
const message = verification.reason === "missing-token"
? "请先完成安全验证"
: "安全验证未通过"
return NextResponse.json({ error: message }, { status: 400 })
}
const user = await register(username, password)
return NextResponse.json({ user })
@@ -27,4 +37,4 @@ export async function POST(request: Request) {
{ status: 500 }
)
}
}
}