import { ArrowRight, LogOut, ShieldCheck } from "lucide-react"; import { useState } from "react"; import { Link, NavLink, useLocation, useNavigate } from "react-router"; import { authClient, isAdminSession, useSession } from "@/client/lib/auth-client"; import { signInPath } from "@/client/lib/navigation"; import { Skeleton } from "@/client/components/ui/skeleton"; const navLinkClass = ({ isActive }: { isActive: boolean }): string => [ // Stay reachable on small screens by letting the nav row scroll // horizontally instead of disappearing behind a hamburger menu — // tessera's nav is short enough to stay visible. "shrink-0 rounded-lg px-3 py-1.5 text-sm font-medium transition-colors", isActive ? "bg-accent-500/10 text-accent-400" : "text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200", ].join(" "); const HeaderBrand = ({ href }: { href: string }) => ( tessera An identification mark. ); const SignInPill = () => { const { pathname, search } = useLocation(); if (pathname === "/sign-in") return null; const here = `${pathname}${search}`; return ( Sign in ); }; interface SignedInUserProps { name: string; email: string; refetch: () => void; } const SignedInUser = ({ name, email, refetch }: SignedInUserProps) => { const navigate = useNavigate(); const [signingOut, setSigningOut] = useState(false); const [failed, setFailed] = useState(false); const handleSignOut = async () => { if (signingOut) return; setSigningOut(true); setFailed(false); try { await authClient.signOut(); // Better Auth's signOut clears the cookie server-side but doesn't push // the cleared state into the nanostore. Refetch so the header (and any // other useSession consumer) sees the user is gone before we navigate. await refetch(); navigate("/"); } catch { // Server may have cleared the session even if our response path tripped. // Refetch first so the header reflects server truth — if the session is // actually gone, this component unmounts before the failed label paints. try { await refetch(); } catch { // ignore: the failed label still surfaces the sign-out failure even // if refetch itself errors. } setFailed(true); } finally { setSigningOut(false); } }; const display = name.trim() || email; const buttonClass = failed ? "inline-flex items-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-2.5 py-1.5 text-xs text-red-300 transition-colors hover:border-red-500/50 hover:bg-red-500/20 hover:text-red-200 disabled:cursor-not-allowed disabled:opacity-60" : "inline-flex items-center gap-1.5 rounded-lg border border-zinc-800/60 bg-zinc-900/70 px-2.5 py-1.5 text-xs text-zinc-300 transition-colors hover:border-zinc-700/60 hover:bg-zinc-800/60 hover:text-zinc-100 disabled:cursor-not-allowed disabled:opacity-60"; const label = signingOut ? "Signing out..." : failed ? "Retry sign-out" : "Sign out"; return (