File tree 7 files changed +27
-18
lines changed
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>(
79
79
? AbortSignal . timeout ( ABORT_MS )
80
80
: abortPolyfill ( ABORT_MS ) ,
81
81
credentials : 'include' ,
82
+ cache : 'no-store' ,
82
83
} ) ;
83
84
84
85
return ( data . body as unknown as SuccessType < R > ) . data ;
85
86
} catch ( err : unknown ) {
86
87
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 ) {
92
89
window . location . replace ( '/' ) ;
93
90
}
94
-
91
+ //context.status === 401 ||
95
92
setContext ( 'Request' , {
96
93
path : context . url ,
97
94
status : context . status ,
Original file line number Diff line number Diff line change 1
1
import { ReactElement } from 'react' ;
2
2
import { dehydrate , HydrationBoundary } from '@tanstack/react-query' ;
3
- import { Header } from '@/components' ;
4
3
import { PATHS } from '@/constants' ;
5
4
import { me } from '@/apis' ;
6
5
import { getQueryClient } from '@/utils/queryUtil' ;
6
+ import { Header } from '@/components' ;
7
7
8
8
interface IProp {
9
9
children : ReactElement ;
Original file line number Diff line number Diff line change 3
3
import { useRouter } from 'next/navigation' ;
4
4
import { useForm } from 'react-hook-form' ;
5
5
import Image from 'next/image' ;
6
- import { useMutation } from '@tanstack/react-query' ;
6
+ import { useMutation , useQueryClient } from '@tanstack/react-query' ;
7
7
import { Input , Button } from '@/components' ;
8
8
import { LoginVo } from '@/types' ;
9
9
import { login , sampleLogin } from '@/apis' ;
@@ -14,6 +14,7 @@ const responsiveStyle =
14
14
15
15
export const Content = ( ) => {
16
16
const { replace } = useRouter ( ) ;
17
+ const client = useQueryClient ( ) ;
17
18
18
19
const {
19
20
register,
@@ -22,6 +23,7 @@ export const Content = () => {
22
23
} = useForm < LoginVo > ( { mode : 'all' } ) ;
23
24
24
25
const onSuccess = ( ) => {
26
+ client . clear ( ) ;
25
27
trackUserEvent ( MessageEnum . LOGIN ) ;
26
28
replace ( '/main?asc=false&sort=' ) ;
27
29
} ;
Original file line number Diff line number Diff line change @@ -32,20 +32,28 @@ export const Header = () => {
32
32
const path = usePathname ( ) ;
33
33
const router = useRouter ( ) ;
34
34
const width = useResponsive ( ) ;
35
- const client = useQueryClient ( ) ;
36
35
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 ( ) ;
43
37
44
38
const { data : profiles } = useQuery ( {
45
39
queryKey : [ PATHS . ME ] ,
46
40
queryFn : me ,
47
41
} ) ;
48
42
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
+
49
57
useEffect ( ( ) => {
50
58
const handleClickOutside = ( e : MouseEvent ) =>
51
59
open &&
Original file line number Diff line number Diff line change 1
- export * from './header' ;
1
+ export * from '.// header' ;
2
2
export * from './main' ;
3
3
export * from './leaderboards' ;
Original file line number Diff line number Diff line change @@ -3,14 +3,15 @@ import { toast } from 'react-toastify';
3
3
4
4
let localQueryClient : QueryClient | undefined ;
5
5
const STALE_TIME = 1000 * 60 * 3 ;
6
- const GC_TIME = 1000 * 60 * 30 ;
6
+ const GC_TIME = 1000 ;
7
7
8
8
const createQueryClient = ( ) =>
9
9
new QueryClient ( {
10
10
defaultOptions : {
11
11
queries : {
12
12
retry : 1 ,
13
- refetchOnWindowFocus : false ,
13
+ refetchOnWindowFocus : true ,
14
+ refetchOnMount : true ,
14
15
staleTime : STALE_TIME ,
15
16
gcTime : GC_TIME ,
16
17
} ,
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export const trackUserEvent = (event: keyof typeof MessageEnum | number) => {
28
28
instance ( '/event' , {
29
29
body : { eventType } ,
30
30
method : 'POST' ,
31
+ keepalive : true ,
31
32
} ) ;
32
33
}
33
34
} ;
You can’t perform that action at this time.
0 commit comments