import { setSessionToken } from "@/lib/session"; import { BackendError, backendRequest } from "@/lib/backend"; import type { LoginResponse } from "@/lib/types"; export async function POST(request: Request) { try { const body = await request.json(); const result = await backendRequest("/auth/employee/login", { method: "POST", body: JSON.stringify({ username: body.username, password: body.password }), token: "" }); await setSessionToken(result.token); return Response.json({ success: true, data: { user: result.user, tokenType: result.tokenType, expiresIn: result.expiresIn } }); } catch (error) { const status = error instanceof BackendError ? error.status : 500; const message = error instanceof Error ? error.message : "登录失败"; return Response.json({ success: false, data: null, message }, { status }); } }