From 4ec97a92ab89f89c935350c7177954045e37efdf Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Sat, 16 May 2026 17:11:35 +0800 Subject: [PATCH] feat: conditionally hide admin-only nav items for moderator role --- components/manage/manage-sidebar.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/manage/manage-sidebar.tsx b/components/manage/manage-sidebar.tsx index 5c9de1a..d377440 100644 --- a/components/manage/manage-sidebar.tsx +++ b/components/manage/manage-sidebar.tsx @@ -2,6 +2,7 @@ import Link from "next/link" import { usePathname } from "next/navigation" +import { useSession } from "@/lib/auth-client" import { UsersIcon, CpuIcon, @@ -17,7 +18,7 @@ import { type NavItem = | { type: "section"; label: string } | { type: "divider" } - | { type: "link"; href: string; label: string; icon: React.ElementType } + | { type: "link"; href: string; label: string; icon: React.ElementType; adminOnly?: boolean } const navItems: NavItem[] = [ { type: "section", label: "Overview" }, @@ -29,7 +30,7 @@ const navItems: NavItem[] = [ }, { type: "divider" }, { type: "section", label: "Management" }, - { type: "link", href: "/manage/users", label: "Users", icon: UsersIcon }, + { type: "link", href: "/manage/users", label: "Users", icon: UsersIcon, adminOnly: true }, { type: "link", href: "/manage/hardware", @@ -41,6 +42,7 @@ const navItems: NavItem[] = [ href: "/manage/storage", label: "Storage", icon: HardDriveIcon, + adminOnly: true, }, { type: "link", href: "/manage/games", label: "Games", icon: Gamepad2Icon }, { type: "divider" }, @@ -68,6 +70,9 @@ const navItems: NavItem[] = [ export function ManageSidebar() { const pathname = usePathname() + const { data: session } = useSession() + const role = session?.user?.role ?? "user" + const isAdmin = role === "admin" return (