Files
ADCTESTAPP/app/api/auth/login/route.ts
T

26 lines
659 B
TypeScript

import { NextResponse } from "next/server";
import { SESSION_COOKIE } from "@/lib/auth";
export async function POST(request: Request) {
const body = await request.json().catch(() => null);
if (body?.username !== "admin" || body?.password !== "admin") {
return NextResponse.json(
{ error: "invalid_credentials" },
{ status: 401 },
);
}
const response = NextResponse.json({ success: true });
response.cookies.set({
name: SESSION_COOKIE,
value: "authenticated",
httpOnly: true,
sameSite: "lax",
secure: process.env.NODE_ENV === "production",
maxAge: 60 * 60 * 8,
path: "/",
});
return response;
}