import { NextRequest, NextResponse } from "next/server"; import { adminCookieOptions, createAdminSessionValue } from "@/lib/adminAuth"; export async function POST(request: NextRequest) { try { const adminPassword = process.env.ADMIN_PASSWORD || ""; if (!adminPassword) { return NextResponse.json({ error: "ADMIN_PASSWORD is not set" }, { status: 500 }); } const body = await request.json(); const password = typeof body?.password === "string" ? body.password : ""; if (password !== adminPassword) { return NextResponse.json({ error: "Invalid password" }, { status: 401 }); } const response = NextResponse.json({ ok: true }); response.cookies.set({ ...adminCookieOptions(), value: createAdminSessionValue(), }); return response; } catch (error) { console.error("Admin login error:", error); return NextResponse.json({ error: "Failed to login" }, { status: 500 }); } }