diff --git a/client/src/components/Header.tsx b/client/src/components/Header.tsx new file mode 100644 index 0000000..8abc6c2 --- /dev/null +++ b/client/src/components/Header.tsx @@ -0,0 +1,133 @@ +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 ( + <> + + + + + + + + + + + + + + + + {isAuthenticated && user ? ( + <> + + Admin Dashboard + + + + + + {user.firstName} {user.lastName} + + + + + + + > + ) : ( + setIsLoginModalOpen(true)} + data-testid="button-login" + > + Login + + )} + + + + + + + + + + {/* Login Modal */} + setIsLoginModalOpen(false)} + /> + > + ); +} \ No newline at end of file