"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { motion } from "framer-motion"; import { useTheme } from "next-themes"; import { useState, useEffect } from "react"; import { Lock, Sun, Moon, Menu, X, LogOut } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { api } from "@/lib/api-client"; import { User } from "@/lib/types"; const NAV_LINKS = [ { href: "/", label: "Home" }, { href: "/snippets", label: "Snippets" }, { href: "/snippets/new", label: "New" }, ]; export function Header() { const pathname = usePathname(); const { theme, setTheme } = useTheme(); const [mounted, setMounted] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); const [user, setUser] = useState(null); useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect setMounted(true); api.me().then(({ user }) => setUser(user)).catch(() => setUser(null)); }, [pathname]); const handleLogout = async () => { await api.logout(); setUser(null); window.location.href = "/login"; }; if (pathname.startsWith("/s/")) return null; return (
CVault
{mounted && ( )} {user ? ( ) : ( )}
{mobileOpen && (
{NAV_LINKS.map((link) => ( setMobileOpen(false)}> ))} {user ? ( ) : ( setMobileOpen(false)}> )}
)}
); }