import { redirect } from "next/navigation"; import { auth } from "@/auth"; import { StaffShell } from "@/components/navigation/staff-shell"; import { getNavRole, hasPermission } from "@/lib/auth/permissions"; import { Permission } from "@/generated/prisma/enums"; import { prisma } from "@/lib/db/prisma"; import { getNavItems } from "@/lib/navigation/nav-config"; import { getUnreadNotificationCount } from "@/services/notifications/notification.service"; /** * Owner and Super Administrator are permissions, not separate account * types (see docs/implementation-plan.md §3, §11) — this layout reuses the * exact same shell/nav as (staff), and only adds a permission check on * top. There is no "switch to owner tools" control anywhere in the app — * a user who can manage staff simply sees "Manage" in their one merged * nav (see lib/navigation/nav-config.ts). */ export default async function OwnerLayout({ children }: { children: React.ReactNode }) { const session = await auth(); if (!session?.user) { redirect("/sign-in?callbackUrl=/owner"); } const canManageStaff = await hasPermission(session.user.id, Permission.MANAGE_STAFF); if (!canManageStaff) { redirect("/staff"); } const role = (await getNavRole(session.user.id)) ?? "owner"; const unreadNotificationCount = await getUnreadNotificationCount(prisma, session.user.id); return ( {children} ); }