/** /api/admin/password — 修改后台密码。 */ import { NextResponse } from "next/server"; import { changeAdminPassword, getSession, verifyCsrf } from "@/lib/auth"; export const runtime = "nodejs"; export async function PUT(req: Request) { const session = await getSession(); if (!session || !(await verifyCsrf())) { return NextResponse.json({ error: "未登录" }, { status: 401 }); } let body: { password?: string }; try { body = await req.json(); } catch { return NextResponse.json({ error: "请求格式错误" }, { status: 400 }); } const password = String(body.password ?? ""); if (password.length < 8) { return NextResponse.json({ error: "密码至少 8 位" }, { status: 400 }); } await changeAdminPassword(session.user_id, password); return NextResponse.json({ ok: true }); }