"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { LayoutDashboard, Building2, BellRing, Settings, LogOut, Rocket, Megaphone } from "lucide-react"; import { api, getToken, setToken } from "@/lib/api"; import { Logo } from "@/components/ui"; type Me = { id: string; name: string; email: string }; const NAV = [ { href: "/", label: "Installs", icon: LayoutDashboard }, { href: "/customers", label: "Customers", icon: Building2 }, { href: "/alerts", label: "Alerts", icon: BellRing }, { href: "/releases", label: "Releases", icon: Rocket }, { href: "/notices", label: "Notices", icon: Megaphone }, { href: "/settings", label: "Settings", icon: Settings }, ]; /** Everything except /login: requires a session, with the side navigation. */ export default function HubLayout({ children }: { children: React.ReactNode }) { const router = useRouter(); const pathname = usePathname(); const [me, setMe] = useState(null); useEffect(() => { if (!getToken()) { router.replace("/login"); return; } api("/api/auth/me").then(setMe).catch(() => router.replace("/login")); }, [router]); if (!me) return
Loading…
; const active = (href: string) => (href === "/" ? pathname === "/" || pathname.startsWith("/installs") : pathname.startsWith(href)); return (
{/* Pinned to the window, so Sign out stays in view however long the page is. */}
{children}
); }