import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Search, Settings, User, LogOut } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { useToast } from "@/hooks/use-toast"; import { queryClient } from "@/lib/queryClient"; import LoginModal from "@/components/LoginModal"; export default function Header() { const { user, isAuthenticated } = useAuth(); const { toast } = useToast(); const [isLoginModalOpen, setIsLoginModalOpen] = useState(false); const handleAdminPage = () => { window.location.href = "/admin"; }; const handleLogout = async () => { try { const response = await fetch("/api/logout", { method: "POST", credentials: "include", }); if (response.ok) { toast({ title: "로그아웃 성공", description: "안전하게 로그아웃되었습니다.", }); // Invalidate all auth-related queries queryClient.invalidateQueries({ queryKey: ["/api/auth/user"] }); // Redirect to home window.location.href = "/"; } else { throw new Error("로그아웃 실패"); } } catch (error) { toast({ title: "로그아웃 오류", description: "로그아웃 중 오류가 발생했습니다.", variant: "destructive", }); } }; return ( <>
SAPIENS
{isAuthenticated && user ? ( <>
{user.firstName} {user.lastName}
) : ( )}
{/* Login Modal */} setIsLoginModalOpen(false)} /> ); }