first commit
This commit is contained in:
15
lib/auth-helpers.ts
Normal file
15
lib/auth-helpers.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user