import Link from 'next/link'; import { redirect } from 'next/navigation'; import { headers } from 'next/headers'; import { eq } from 'drizzle-orm'; import { ShieldX } from 'lucide-react'; import { auth } from '@/lib/auth'; import { db } from '@/lib/db'; import { userProfiles } from '@/lib/db/schema/users'; import { Button } from '@/components/ui/button'; /** * Guard: only super-admins (isSuperAdmin === true in user_profiles) may * access any page under /[portSlug]/admin. * * H-15: previously this layout silently redirected non-admins to * `/dashboard`, which left them staring at the dashboard with no * explanation of why their bookmark / shared admin link "didn't work". * Render an explicit 403 page instead so the URL stays on the failed * route and the user can see why their request was denied. */ export default async function AdminLayout({ children, params, }: { children: React.ReactNode; params: Promise<{ portSlug: string }>; }) { const { portSlug } = await params; const session = await auth.api.getSession({ headers: await headers() }); if (!session?.user) { redirect('/login'); } const profile = await db.query.userProfiles.findFirst({ where: eq(userProfiles.userId, session.user.id), }); if (!profile?.isSuperAdmin) { return (

Access denied

This area is for super-administrators only. If you believe you should have access, ask an administrator to grant the super-admin role on your account.

); } return <>{children}; }