File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
use-notification/use-notification-get-unread-count Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import axios, { AxiosError } from 'axios';
88import Cookies from 'js-cookie' ;
99
1010import { API } from '@/api' ;
11+ import { useAuth } from '@/providers' ;
1112import { LoginRequest } from '@/types/service/auth' ;
1213import { CommonErrorResponse } from '@/types/service/common' ;
1314
@@ -53,6 +54,8 @@ export const useLogin = () => {
5354 const [ loginError , setLoginError ] = useState < string | null > ( null ) ;
5455 const clearLoginError = useCallback ( ( ) => setLoginError ( null ) , [ ] ) ;
5556
57+ const { accessToken } = useAuth ( ) ;
58+
5659 const handleLogin = async ( payload : LoginRequest , formApi : { reset : ( ) => void } ) => {
5760 setLoginError ( null ) ;
5861
@@ -70,6 +73,7 @@ export const useLogin = () => {
7073 formApi . reset ( ) ;
7174 const nextPath = normalizePath ( searchParams . get ( 'path' ) ) ;
7275 router . replace ( nextPath ) ;
76+ accessToken . set ( result . accessToken ) ;
7377 } catch ( error ) {
7478 if ( isCommonErrorResponse ( error ) ) {
7579 console . error ( '[LOGIN ERROR]' , error . errorCode , error . detail ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,18 @@ import { useQueryClient } from '@tanstack/react-query';
66
77import { API } from '@/api' ;
88import { userKeys } from '@/lib/query-key/query-key-user' ;
9+ import { useAuth } from '@/providers' ;
910
1011export const useLogout = ( ) => {
1112 const router = useRouter ( ) ;
1213 const queryClient = useQueryClient ( ) ;
1314
15+ const { accessToken } = useAuth ( ) ;
16+
1417 const handleLogout = async ( ) => {
1518 try {
1619 await API . authService . logout ( ) ;
20+ accessToken . remove ( ) ;
1721 } catch ( error ) {
1822 console . error ( '[LOGOUT ERROR]' , error ) ;
1923 } finally {
Original file line number Diff line number Diff line change @@ -2,14 +2,21 @@ import { useQuery } from '@tanstack/react-query';
22
33import { API } from '@/api' ;
44import { notificationKeys } from '@/lib/query-key/query-key-notification' ;
5+ import { useAuth } from '@/providers' ;
56
67export const useGetNotificationUnreadCount = ( ) => {
7- const isAuthenticated = typeof window !== 'undefined' && document . cookie . includes ( 'accessToken' ) ;
8-
9- return useQuery ( {
8+ const { accessToken } = useAuth ( ) ;
9+ const queryResult = useQuery ( {
1010 queryKey : notificationKeys . unReadCount ( ) ,
1111 queryFn : ( ) => API . notificationService . getUnreadCount ( ) ,
12- retry : false , // 재시도 안 함
13- enabled : isAuthenticated ,
12+ retry : false ,
13+ enabled : ! ! accessToken . value ,
1414 } ) ;
15+
16+ const finalData = accessToken . value ? queryResult . data : 0 ;
17+
18+ return {
19+ ...queryResult ,
20+ data : finalData ,
21+ } ;
1522} ;
You can’t perform that action at this time.
0 commit comments