11import React , { useState , useEffect } from 'react' ;
22import { useNavigate } from 'react-router-dom' ;
33import { useLoginModal } from '../../hooks/useModal' ;
4+ import { useAuth , useLogout } from '../../hooks/useAuth' ;
45
56const Header : React . FC = ( ) => {
67 const { openLoginModal } = useLoginModal ( ) ;
78 const [ isScrolled , setIsScrolled ] = useState ( false ) ;
89 const navigate = useNavigate ( ) ;
10+
11+ // 인증 상태와 로그아웃 기능 가져오기
12+ const { isAuthenticated, isLoading } = useAuth ( ) ;
13+ const logoutMutation = useLogout ( ) ;
14+
15+ // 디버깅용 로그
16+ React . useEffect ( ( ) => {
17+ console . log ( '🎯 Header auth state:' , { isAuthenticated, isLoading } ) ;
18+ } , [ isAuthenticated , isLoading ] ) ;
19+
20+ // 로그아웃 핸들러
21+ const handleLogout = async ( ) => {
22+ try {
23+ console . log ( '🚪 User clicked logout button' ) ;
24+ await logoutMutation . mutateAsync ( ) ;
25+ console . log ( '✅ Logout completed successfully' ) ;
26+ navigate ( '/' ) ; // 로그아웃 후 홈으로 이동
27+ } catch ( error ) {
28+ console . error ( '❌ 로그아웃 실패:' , error ) ;
29+ // 에러가 발생해도 홈으로 이동 (사용자 경험 개선)
30+ navigate ( '/' ) ;
31+ }
32+ } ;
933
1034 useEffect ( ( ) => {
1135 const handleScroll = ( ) => {
@@ -28,7 +52,7 @@ const Header: React.FC = () => {
2852 borderBottom : isScrolled ? '1px solid rgba(229, 231, 235, 0.8)' : '1px solid transparent'
2953 } }
3054 >
31- < div className = "max-w-6xl mx-auto px-5 py-4 flex items-center justify-between" >
55+ < div className = "max-w-6xl mx-auto px-3 sm:px-5 py-3 sm: py-4 flex items-center justify-between" >
3256 < div className = "flex items-center space-x-3" >
3357 < div
3458 className = "flex items-center cursor-pointer"
@@ -37,17 +61,43 @@ const Header: React.FC = () => {
3761 < img
3862 src = "/cs25.png"
3963 alt = "CS25"
40- className = "h-8 w-auto"
64+ className = "h-6 sm:h- 8 w-auto"
4165 />
4266 </ div >
4367 </ div >
4468
45- < button
46- onClick = { openLoginModal }
47- className = "px-6 py-2 rounded-lg font-medium transition-all duration-300 bg-gradient-to-r from-brand-500 to-brand-600 text-white hover:from-brand-600 hover:to-brand-700 shadow-sm"
48- >
49- 로그인
50- </ button >
69+ < div className = "flex items-center space-x-2 sm:space-x-4" >
70+ { isAuthenticated ? (
71+ // 로그인된 상태
72+ < div className = "flex items-center space-x-2 sm:space-x-3" >
73+ < button
74+ onClick = { ( ) => navigate ( '/profile' ) }
75+ className = "px-2 sm:px-4 py-1.5 sm:py-2 rounded-lg font-medium transition-all duration-300 text-gray-700 hover:text-brand-600 hover:bg-brand-50 text-sm sm:text-base"
76+ >
77+ < span className = "sm:inline" > 마이페이지</ span >
78+ </ button >
79+ < button
80+ onClick = { handleLogout }
81+ disabled = { logoutMutation . isPending }
82+ className = { `px-3 sm:px-6 py-1.5 sm:py-2 rounded-lg font-medium transition-all duration-300 text-sm sm:text-base ${
83+ logoutMutation . isPending
84+ ? 'bg-gray-400 text-white cursor-not-allowed'
85+ : 'bg-gradient-to-r from-brand-500 to-brand-600 text-white hover:from-brand-600 hover:to-brand-700 shadow-sm'
86+ } `}
87+ >
88+ 로그아웃
89+ </ button >
90+ </ div >
91+ ) : (
92+ // 로그인되지 않은 상태
93+ < button
94+ onClick = { openLoginModal }
95+ className = "px-4 sm:px-6 py-1.5 sm:py-2 rounded-lg font-medium transition-all duration-300 bg-gradient-to-r from-brand-500 to-brand-600 text-white hover:from-brand-600 hover:to-brand-700 shadow-sm text-sm sm:text-base"
96+ >
97+ 로그인
98+ </ button >
99+ ) }
100+ </ div >
51101 </ div >
52102 </ header >
53103 ) ;
0 commit comments