"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; const items = [ { href: "/overview", label: "Overview", icon: "🏠" }, { href: "/machines", label: "Machines", icon: "🏭" }, { href: "/reports", label: "Reports", icon: "📊" }, { href: "/settings", label: "Settings", icon: "⚙️" }, ]; export function Sidebar() { const pathname = usePathname(); const router = useRouter(); const [me, setMe] = useState<{ user?: { name?: string | null; email?: string | null }; org?: { name?: string | null }; membership?: { role?: string | null }; } | null>(null); useEffect(() => { let alive = true; async function loadMe() { try { const res = await fetch("/api/me", { cache: "no-store" }); const data = await res.json().catch(() => ({})); if (alive && res.ok && data?.ok) { setMe(data); } } catch { if (alive) setMe(null); } } loadMe(); return () => { alive = false; }; }, []); async function onLogout() { await fetch("/api/logout", { method: "POST" }); router.push("/login"); router.refresh(); } return ( ); }