25 lines
633 B
TypeScript
25 lines
633 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getSession } from "@/lib/auth";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const { password } = await req.json();
|
|
|
|
if (password !== process.env.PASSWORD) {
|
|
return NextResponse.json({ error: "Invalid password" }, { status: 401 });
|
|
}
|
|
|
|
const session = await getSession();
|
|
session.authenticated = true;
|
|
await session.save();
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
console.error(error);
|
|
return NextResponse.json(
|
|
{ error: "Authentication failed" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|