diff --git a/src/app/(auth)/register/actions.ts b/src/app/(auth)/register/actions.ts index c59de8b..68463eb 100644 --- a/src/app/(auth)/register/actions.ts +++ b/src/app/(auth)/register/actions.ts @@ -21,21 +21,27 @@ export async function registerUser(input: unknown): Promise { + const userCount = await tx.user.count(); + const role = userCount === 0 ? "ADMIN" : "USER"; + + return tx.user.create({ + data: { + name: parsed.data.name, + email: parsed.data.email, + hashedPassword, + role, + settings: { + create: { + lowStockThreshold: 10, + currency: "USD", + theme: "dark", + units: "metric", + }, }, }, - }, + }); }); return { success: true, data: { id: user.id } }; diff --git a/src/components/layout/mobile-sidebar.tsx b/src/components/layout/mobile-sidebar.tsx index 93c0043..a77d002 100644 --- a/src/components/layout/mobile-sidebar.tsx +++ b/src/components/layout/mobile-sidebar.tsx @@ -2,6 +2,7 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; +import { useSession } from "next-auth/react"; import { LayoutDashboard, Cylinder, @@ -17,27 +18,17 @@ import { Flame, } from "lucide-react"; import { cn } from "@/lib/utils"; -import { APP_NAME } from "@/lib/constants"; +import { APP_NAME, NAV_ITEMS } from "@/lib/constants"; import { SheetHeader, SheetTitle } from "@/components/ui/sheet"; const icons = { LayoutDashboard, Cylinder, Droplets, Paintbrush, Gem, FileBox, Send, ClipboardList, Building2, MapPin, Settings }; -const navItems = [ - { label: "Dashboard", href: "/dashboard", icon: "LayoutDashboard" as const }, - { label: "Filaments", href: "/filaments", icon: "Cylinder" as const }, - { label: "Resins", href: "/resins", icon: "Droplets" as const }, - { label: "Paints", href: "/paints", icon: "Paintbrush" as const }, - { label: "Supplies", href: "/supplies", icon: "Gem" as const }, - { label: "STL Files", href: "/stls", icon: "FileBox" as const }, - { label: "Telegram", href: "/telegram", icon: "Send" as const }, - { label: "Usage", href: "/usage", icon: "ClipboardList" as const }, - { label: "Vendors", href: "/vendors", icon: "Building2" as const }, - { label: "Locations", href: "/locations", icon: "MapPin" as const }, - { label: "Settings", href: "/settings", icon: "Settings" as const }, -]; - export function MobileSidebar() { const pathname = usePathname(); + const { data: session } = useSession(); + const isAdmin = session?.user?.role === "ADMIN"; + + const visibleItems = NAV_ITEMS.filter((item) => !item.adminOnly || isAdmin); return (
@@ -48,7 +39,7 @@ export function MobileSidebar() {