Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import { getServerSession } from "next-auth/next";
import { authOptions } from "./auth";
export async function getServerAuthSession() {
return await getServerSession(authOptions);
}
export async function requireAuth() {
const session = await getServerAuthSession();
if (!session || !session.user) {
throw new Error("Unauthorized");
}
return session;
}
export async function requireAdmin() {
const session = await requireAuth();
if (session.user.role !== "admin") {
throw new Error("Forbidden - Admin access required");
}
return session;
}
|