import "server-only";
import { redirect } from "next/navigation";
import { auth } from "./auth";

export async function requireAdmin() {
  const session = await auth().catch(() => null);
  const role = (session?.user as { role?: string } | undefined)?.role;
  if (!session?.user || role !== "admin") redirect("/login");
  return session;
}

export async function requireUser() {
  const session = await auth().catch(() => null);
  if (!session?.user) redirect("/login");
  return session;
}
