mirror of
https://github.com/beilunyang/moemail.git
synced 2026-05-27 03:00:05 +08:00
feat(turnstile): integrate Cloudflare Turnstile for enhanced security in login and registration processes
This commit is contained in:
@@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user