16 lines
527 B
TypeScript
16 lines
527 B
TypeScript
import { getServerSession } from "next-auth";
|
|
import { NextResponse } from "next/server";
|
|
import { authOptions } from "./auth";
|
|
|
|
export async function requireSession() {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.email) {
|
|
return { session: null, response: NextResponse.json({ error: "Unauthorized" }, { status: 401 }) };
|
|
}
|
|
return { session, response: null };
|
|
}
|
|
|
|
export function isAdminSession(session: { user?: { role?: string } } | null) {
|
|
return session?.user?.role === "ADMIN";
|
|
}
|