@@ -6,44 +6,43 @@ import { useRouter } from 'next/navigation';
66import tw from '@/shared/utills/tw' ;
77import { useAuthStore } from '@/domains/shared/store/auth' ;
88import { setPreLoginPath } from '@/domains/shared/auth/utils/setPreLoginPath' ;
9- import { useEffect , useState } from 'react' ;
9+ import { useEffect , useState } from 'react' ;
1010import LogoutConfirm from '@/domains/login/components/LogoutConfirm' ;
1111import { getApi } from '@/app/api/config/appConfig' ;
1212
13-
1413function HeaderBtn ( { pathname } : { pathname : string } ) {
1514 const { isLoggedIn } = useAuthStore ( ) ;
1615 const router = useRouter ( ) ;
1716 const [ logoutModalOpen , setLogoutModalOpen ] = useState ( false ) ;
18- const [ hasNewNotification , setHasNotification ] = useState ( false )
17+ const [ hasNewNotification , setHasNotification ] = useState ( false ) ;
18+
19+ useEffect ( ( ) => {
20+ if ( ! isLoggedIn ) return ;
1921
20- useEffect ( ( ) => {
21- if ( ! isLoggedIn ) return ;
22+ console . log ( '🔌 SSE 연결 시작...' ) ;
23+ const eventSource = new EventSource ( ` ${ getApi } /me/subscribe` , { withCredentials : true } ) ;
2224
23- console . log ( '🔌 SSE 연결 시작...' ) ;
24- const eventSource = new EventSource ( `${ getApi } /me/subscribe` , { withCredentials : true } ) ;
25+ eventSource . onopen = ( ) => {
26+ console . log ( '✅ SSE 연결 성공!' ) ;
27+ } ;
2528
26- eventSource . onopen = ( ) => {
27- console . log ( '✅ SSE 연결 성공!' ) ;
28- } ;
29+ eventSource . onmessage = ( event ) => {
30+ console . log ( '📢 새 알림 도착:' , event . data ) ;
31+ setHasNotification ( true ) ;
32+ } ;
2933
30- eventSource . onmessage = ( event ) => {
31- console . log ( '📢 새 알림 도착:' , event . data ) ;
32- setHasNotification ( true ) ;
33- } ;
34+ eventSource . onerror = ( error ) => {
35+ console . error ( '❌ SSE 에러:' , error ) ;
36+ console . log ( '연결 상태:' , eventSource . readyState ) ; // 0: CONNECTING, 1: OPEN, 2: CLOSED
37+ eventSource . close ( ) ;
38+ } ;
3439
35- eventSource . onerror = ( error ) => {
36- console . error ( '❌ SSE 에러:' , error ) ;
37- console . log ( '연결 상태:' , eventSource . readyState ) ; // 0: CONNECTING, 1: OPEN, 2: CLOSED
38- eventSource . close ( ) ;
39- } ;
40+ return ( ) => {
41+ console . log ( '🔌 SSE 연결 종료' ) ;
42+ eventSource . close ( ) ;
43+ } ;
44+ } , [ isLoggedIn ] ) ;
4045
41- return ( ) => {
42- console . log ( '🔌 SSE 연결 종료' ) ;
43- eventSource . close ( ) ;
44- } ;
45- } , [ isLoggedIn ] ) ;
46-
4746 useEffect ( ( ) => {
4847 const timer = setTimeout ( ( ) => {
4948 console . log ( '🧪 테스트 알림 발생' ) ;
@@ -60,20 +59,19 @@ function HeaderBtn({ pathname }: { pathname: string }) {
6059 className : pathname === '/mypage/my-alarm' ? 'text-tertiary' : 'text-current' ,
6160 hiddenMobile : true ,
6261 onClick : ( ) => {
63- setHasNotification ( false )
64- router . push ( '/mypage/my-alarm' )
62+ setHasNotification ( false ) ;
63+ router . push ( '/mypage/my-alarm' ) ;
6564 } ,
66- showBadge :true
65+ showBadge : true ,
6766 } ,
6867 {
6968 icon : User ,
7069 label : '마이 페이지' ,
7170 className : pathname === '/mypage' ? 'text-tertiary' : 'text-current' ,
7271 hiddenMobile : true ,
7372 onClick : ( ) => router . push ( '/mypage' ) ,
74- showBadge :false
73+ showBadge : false ,
7574 } ,
76-
7775 ] ;
7876
7977 const authButton = isLoggedIn
0 commit comments