Skip to content

Commit 72ed6e3

Browse files
committed
hotfix: 캐싱 관련 문제 의심 항목 수정
1 parent 3583236 commit 72ed6e3

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

src/apis/instance.request.ts

+3-6
Original file line numberDiff line numberDiff 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,

src/app/(with-tracker)/(auth-required)/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ReactElement } from 'react';
22
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
3-
import { Header } from '@/components';
43
import { PATHS } from '@/constants';
54
import { me } from '@/apis';
65
import { getQueryClient } from '@/utils/queryUtil';
6+
import { Header } from '@/components';
77

88
interface IProp {
99
children: ReactElement;

src/app/(with-tracker)/(login)/Content.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useRouter } from 'next/navigation';
44
import { useForm } from 'react-hook-form';
55
import Image from 'next/image';
6-
import { useMutation } from '@tanstack/react-query';
6+
import { useMutation, useQueryClient } from '@tanstack/react-query';
77
import { Input, Button } from '@/components';
88
import { LoginVo } from '@/types';
99
import { login, sampleLogin } from '@/apis';
@@ -14,6 +14,7 @@ const responsiveStyle =
1414

1515
export 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
};

src/components/auth-required/header/index.tsx

+15-7
Original file line numberDiff line numberDiff 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 &&

src/components/auth-required/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './header';
1+
export * from './/header';
22
export * from './main';
33
export * from './leaderboards';

src/utils/queryUtil.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { toast } from 'react-toastify';
33

44
let localQueryClient: QueryClient | undefined;
55
const STALE_TIME = 1000 * 60 * 3;
6-
const GC_TIME = 1000 * 60 * 30;
6+
const GC_TIME = 1000;
77

88
const 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
},

src/utils/trackUtil.tsx

+1
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)