import Link from "next/link"; import { logoutAction } from "@/actions/auth"; import { requireUser } from "@/lib/auth/dal"; import { countCommentsByStatus } from "@/lib/services/comments"; import { getSettings } from "@/lib/services/settings"; const navLinkClasses = "rounded-md px-2.5 py-1.5 text-sm font-medium text-ink transition-colors hover:bg-background hover:text-ink-strong"; /** * Every route in this group is server-guarded: the layout redirects * anonymous visitors, each page calls requireAdmin() again (defense in * depth), and every mutating server action re-checks on its own. */ export default async function AdminLayout({ children }: { children: React.ReactNode }) { const user = await requireUser(); const isAdmin = user.role === "admin"; const canModerate = user.permissions.approveComments; const [settings, commentCounts] = await Promise.all([ getSettings(), canModerate ? countCommentsByStatus(isAdmin ? undefined : { postAuthorId: user.id }) : { pending: 0, approved: 0 }, ]); return ( <> {settings.siteTitle} ยท Admin {/* Authors only manage posts; everything else is the admin's. */} {isAdmin && Dashboard} Posts {isAdmin && ( Pages )} {canModerate && ( Comments {commentCounts.pending > 0 && ( {commentCounts.pending} )} )} {isAdmin && ( <> Users Settings > )} View site | Signed in as{" "} {user.username} Log out {children} > ); }