feat: Implement username/password authentication and registration features

This commit is contained in:
beilunyang
2025-01-15 15:48:26 +08:00
parent 969d0ce334
commit 126a4cb948
24 changed files with 2643 additions and 67 deletions

View File

@@ -0,0 +1,27 @@
import { register } from "@/lib/auth"
import { authSchema } from "@/lib/validation"
import { ZodError } from "zod"
export const runtime = "edge"
export async function POST(request: Request) {
try {
const json = await request.json()
const body = authSchema.parse(json)
await register(body.username, body.password)
return Response.json({ success: true })
} catch (error) {
if (error instanceof ZodError) {
return Response.json(
{ error: error.errors[0].message },
{ status: 400 }
)
}
return Response.json(
{ error: error instanceof Error ? error.message : "注册失败" },
{ status: 500 }
)
}
}