Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/(auth)/_api/auth.queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { postLogin, postLogout } from "./auth.api";

import { userQueryKeys } from "@/shared/api/queries/user";
export const useSocialLogin = () => {
return useMutation({
mutationFn: ({
Expand All @@ -19,6 +19,7 @@ export const useLogout = () => {
mutationFn: postLogout,
onSuccess: () => {
queryClient.clear();
queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() });
},
Comment on lines 20 to 23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

로그아웃 시 in-flight 쿼리 취소 없이 clear만 수행 → 레이스로 인해 사용자 정보가 다시 캐시에 등장할 수 있습니다

queryClient.clear()는 진행 중인 fetch를 취소하지 않습니다. 로그아웃 직전 발행된 userInfo 요청이 응답되면, 캐시가 다시 채워져 PII가 UI에 잠깐 노출될 수 있습니다. 먼저 관련 쿼리를 취소하고 제거하는 순서로 바꾸는 것을 권장합니다. 이 경우 invalidateQueries는 불필요합니다.

-  return useMutation({
+  return useMutation({
     mutationFn: postLogout,
-    onSuccess: () => {
-      queryClient.clear();
-      queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() });
-    },
+    onSuccess: async () => {
+      // 1) 사용자 관련 쿼리 먼저 취소하여 레이스 방지
+      await queryClient.cancelQueries({ queryKey: userQueryKeys.all() });
+      // 2) 사용자 관련 캐시 제거
+      queryClient.removeQueries({ queryKey: userQueryKeys.all() });
+      // 3) (선택) 전역 캐시까지 비우고 싶다면 아래를 사용하되, 퍼블릭 데이터까지 지워지는 점 유의
+      // queryClient.clear();
+    },
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onSuccess: () => {
queryClient.clear();
queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() });
},
return useMutation({
mutationFn: postLogout,
onSuccess: async () => {
// 1) 사용자 관련 쿼리 먼저 취소하여 레이스 방지
await queryClient.cancelQueries({ queryKey: userQueryKeys.all() });
// 2) 사용자 관련 캐시 제거
queryClient.removeQueries({ queryKey: userQueryKeys.all() });
// 3) (선택) 전역 캐시까지 비우고 싶다면 아래를 사용하되, 퍼블릭 데이터까지 지워지는 점 유의
// queryClient.clear();
},
});
🤖 Prompt for AI Agents
In app/(auth)/_api/auth.queries.ts around lines 20 to 23, the logout handler
currently calls queryClient.clear() and invalidateQueries, which doesn't cancel
in-flight fetches and can let a pending userInfo response repopulate the cache;
instead, first call await queryClient.cancelQueries({ queryKey:
userQueryKeys.userInfo() }) to stop any ongoing fetch, then call
queryClient.removeQueries({ queryKey: userQueryKeys.userInfo(), exact: true })
to remove the cached entry; drop the invalidateQueries call (and avoid clear()
unless you also cancel all queries first) so the userInfo cannot reappear after
logout.

});
};
2 changes: 1 addition & 1 deletion shared/api/queries/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ENDPOINTS } from "@/shared/constants/endpoints";
import type { UserInfo } from "@/shared/types/api/user";
import { queryOptions } from "@tanstack/react-query";

const userQueryKeys = {
export const userQueryKeys = {
all: () => ["user"],
userInfo: () => [...userQueryKeys.all(), "userInfo"],
} as const;
Expand Down