File tree Expand file tree Collapse file tree 7 files changed +27
-18
lines changed Expand file tree Collapse file tree 7 files changed +27
-18
lines changed Original file line number Diff line number Diff line change @@ -79,19 +79,16 @@ export const instance = async <I, R>(
7979 ? AbortSignal . timeout ( ABORT_MS )
8080 : abortPolyfill ( ABORT_MS ) ,
8181 credentials : 'include' ,
82+ cache : 'no-store' ,
8283 } ) ;
8384
8485 return ( data . body as unknown as SuccessType < R > ) . data ;
8586 } catch ( err : unknown ) {
8687 const context = err as Response ;
87- if (
88- location &&
89- ! context . ok &&
90- ( context . status === 401 || context . status === 403 )
91- ) {
88+ if ( location && ! context . ok && context . status === 403 ) {
9289 window . location . replace ( '/' ) ;
9390 }
94-
91+ //context.status === 401 ||
9592 setContext ( 'Request' , {
9693 path : context . url ,
9794 status : context . status ,
Original file line number Diff line number Diff line change 11import { ReactElement } from 'react' ;
22import { dehydrate , HydrationBoundary } from '@tanstack/react-query' ;
3- import { Header } from '@/components' ;
43import { PATHS } from '@/constants' ;
54import { me } from '@/apis' ;
65import { getQueryClient } from '@/utils/queryUtil' ;
6+ import { Header } from '@/components' ;
77
88interface IProp {
99 children : ReactElement ;
Original file line number Diff line number Diff line change 33import { useRouter } from 'next/navigation' ;
44import { useForm } from 'react-hook-form' ;
55import Image from 'next/image' ;
6- import { useMutation } from '@tanstack/react-query' ;
6+ import { useMutation , useQueryClient } from '@tanstack/react-query' ;
77import { Input , Button } from '@/components' ;
88import { LoginVo } from '@/types' ;
99import { login , sampleLogin } from '@/apis' ;
@@ -14,6 +14,7 @@ const responsiveStyle =
1414
1515export const Content = ( ) => {
1616 const { replace } = useRouter ( ) ;
17+ const client = useQueryClient ( ) ;
1718
1819 const {
1920 register,
@@ -22,6 +23,7 @@ export const Content = () => {
2223 } = useForm < LoginVo > ( { mode : 'all' } ) ;
2324
2425 const onSuccess = ( ) => {
26+ client . clear ( ) ;
2527 trackUserEvent ( MessageEnum . LOGIN ) ;
2628 replace ( '/main?asc=false&sort=' ) ;
2729 } ;
Original file line number Diff line number Diff line change @@ -32,20 +32,28 @@ export const Header = () => {
3232 const path = usePathname ( ) ;
3333 const router = useRouter ( ) ;
3434 const width = useResponsive ( ) ;
35- const client = useQueryClient ( ) ;
3635 const barWidth = width < SCREENS . MBI ? 65 : 180 ;
37-
38- const { mutate : out } = useMutation ( {
39- mutationFn : logout ,
40- onMutate : ( ) => router . replace ( '/' ) ,
41- onSuccess : ( ) => client . removeQueries ( ) ,
42- } ) ;
36+ const client = useQueryClient ( ) ;
4337
4438 const { data : profiles } = useQuery ( {
4539 queryKey : [ PATHS . ME ] ,
4640 queryFn : me ,
4741 } ) ;
4842
43+ const { mutate : out } = useMutation ( {
44+ mutationFn : logout ,
45+ onSuccess : async ( ) => {
46+ client
47+ . getQueryCache ( )
48+ . findAll ( )
49+ . forEach ( ( query ) => {
50+ client . setQueryData ( query . queryKey , null ) ;
51+ } ) ;
52+ client . clear ( ) ;
53+ router . replace ( '/' ) ;
54+ } ,
55+ } ) ;
56+
4957 useEffect ( ( ) => {
5058 const handleClickOutside = ( e : MouseEvent ) =>
5159 open &&
Original file line number Diff line number Diff line change 1- export * from './header' ;
1+ export * from '.// header' ;
22export * from './main' ;
33export * from './leaderboards' ;
Original file line number Diff line number Diff line change @@ -3,14 +3,15 @@ import { toast } from 'react-toastify';
33
44let localQueryClient : QueryClient | undefined ;
55const STALE_TIME = 1000 * 60 * 3 ;
6- const GC_TIME = 1000 * 60 * 30 ;
6+ const GC_TIME = 1000 ;
77
88const createQueryClient = ( ) =>
99 new QueryClient ( {
1010 defaultOptions : {
1111 queries : {
1212 retry : 1 ,
13- refetchOnWindowFocus : false ,
13+ refetchOnWindowFocus : true ,
14+ refetchOnMount : true ,
1415 staleTime : STALE_TIME ,
1516 gcTime : GC_TIME ,
1617 } ,
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export const trackUserEvent = (event: keyof typeof MessageEnum | number) => {
2828 instance ( '/event' , {
2929 body : { eventType } ,
3030 method : 'POST' ,
31+ keepalive : true ,
3132 } ) ;
3233 }
3334} ;
You can’t perform that action at this time.
0 commit comments