fix: refreshToken 만료 시 UI 동기화되지 않는 이슈 해결#199
Merged
phantom2115 merged 5 commits intodevfrom Feb 15, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 PR 제목
이슈
refreshToken 만료 시 헤더 UI가 동기화되지 않는 이슈가 있었습니다.
user api 요청 실패로 인한 로그인 요청 모달이 뜨면서도 헤더 UI는 로그인 상태를 유지하고 있었습니다. 또한, middleware에서 쿠키를 찾지 못해 redirect 될 때도 마찬가지로 UI 변경이 이루어지지 않았습니다.
해결
기존 구조를 유지하면서 변경하고자 시도했던 일들은 다음과 같습니다.
invalidateQueries: 401 error -> 404 error -> refetch -> 401 error ... 비로그인 상태에서 무한 요청이 발생했습니다.setQueriesData+removeQuery: user queryKey 에 해당하는 data를 null 로 변경 및 캐싱된 데이터 삭제-> 리다이렉트로 인해 header 컴포넌트가 리렌더링될 때만 변경, 이 외에는 UI 변경이 이루어지지 않았습니다.
이 외에도 여러가지 방법을 생각해봤지만..
제가 내린 결론은 react는 상태 기반으로 UI를 업데이트하기 때문에 인증 여부에 대한 상태를 전역 클라이언트 상태로 관리하여 일관적인 UI를 제공하는 것이었습니다.
🔍 변경 사항
useAuthStore관리 : isSignedIn - 현재 로그인 상태인지, 아닌지 판단하는 boolean 값만 관리: 1. 로그인 버튼 클릭 2. 로그아웃 버튼 클릭 3. refreshToken 만료
isSignedIn로 변경api.ts에서 queryClient 접근이 안되는 문제로 인해, 로그인 요청 시 이전 캐싱 데이터 삭제queryClient.clear()하도록 로직 추가🧐 고민되는 부분
REFRESHTOKEN_NOT_FOUND가 비로그인 상태일 때도 발생하다보니 로그아웃이 된 후 모달 혹은 토스트를 띄워주기가 애매하더라구요,, 그래서 일단 로그아웃 처리만 되도록 수정하였습니다.참고했던 글 : React Query는 훌륭하지만, 인증 관리 매니저는 아닙니다