@@ -2,7 +2,7 @@ import { useEffect } from 'react';
2
2
3
3
import { EventSourcePolyfill , NativeEventSource } from 'event-source-polyfill' ;
4
4
5
- import { useLoginInfoStore } from '@stores/loginInfo .store' ;
5
+ import { useTokenStore } from '@stores/accessToken .store' ;
6
6
7
7
export const useEventSource = ( {
8
8
subscribeUrl,
@@ -17,17 +17,17 @@ export const useEventSource = ({
17
17
onmessage ?: EventSourcePolyfill [ 'onmessage' ] ;
18
18
onerror ?: EventSourcePolyfill [ 'onerror' ] ;
19
19
} ) => {
20
- const loginInfo = useLoginInfoStore ( ( state ) => state . loginInfo ) ;
20
+ const accessToken = useTokenStore ( ( state ) => state . accessToken ) ;
21
21
22
22
useEffect ( ( ) => {
23
- if ( ! loginInfo ?. id ) {
23
+ if ( ! accessToken ) {
24
24
return ;
25
25
}
26
26
27
27
const EventSource = EventSourcePolyfill || NativeEventSource ;
28
28
const eventSource = new EventSource ( subscribeUrl , {
29
29
headers : {
30
- Authorization : `Bearer ${ loginInfo . accessToken } ` ,
30
+ Authorization : `Bearer ${ accessToken } ` ,
31
31
'Content-type' : 'text/event-stream' ,
32
32
} ,
33
33
heartbeatTimeout : 1000 * 60 * 60 * 6 ,
@@ -43,5 +43,5 @@ export const useEventSource = ({
43
43
return ( ) => {
44
44
eventSource . close ( ) ;
45
45
} ;
46
- } , [ loginInfo , onmessage , onerror , subscribeUrl , eventListenerParameters ] ) ;
46
+ } , [ accessToken , onmessage , onerror , subscribeUrl , eventListenerParameters ] ) ;
47
47
} ;
0 commit comments