18 lines
492 B
TypeScript
18 lines
492 B
TypeScript
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/lib/auth";
|
|
import { NextResponse } from "next/server";
|
|
|
|
/**
|
|
* Verify that the user is authenticated
|
|
* Returns null if authenticated, or a NextResponse with 401 if not
|
|
*/
|
|
export async function requireAuth(): Promise<NextResponse | null> {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (!session) {
|
|
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
|
}
|
|
|
|
return null;
|
|
}
|