Skip to content

Fix: 로그아웃시 로그인 페이지로 이동#197

Closed
seueooo wants to merge 1 commit into
developfrom
fix/error
Closed

Fix: 로그아웃시 로그인 페이지로 이동#197
seueooo wants to merge 1 commit into
developfrom
fix/error

Conversation

@seueooo
Copy link
Copy Markdown
Contributor

@seueooo seueooo commented Aug 22, 2025

📌 Summary

해당 PR에 대한 작업 내용을 요약하여 작성해주세요.

📚 Tasks

로그아웃시 로그인 페이지로 바로 이동하도록 수정합니다.

Summary by CodeRabbit

  • 버그 수정
    • 로그아웃 후에도 사용자 정보가 화면에 남던 현상을 수정했습니다.
    • 이제 로그아웃 시 사용자 관련 데이터가 즉시 새로고침되어 프로필/메뉴 상태가 정확히 초기화됩니다.
    • 세션 전환 시 캐시 일관성을 향상해, 재로그인 또는 계정 전환 후 잘못된 사용자 정보가 표시되지 않습니다.
    • 로그아웃 직후 새로고침 없이도 헤더, 사이드바 등 공용 영역이 즉시 로그아웃 상태를 반영합니다.
    • 전반적인 로그아웃 경험의 신뢰성과 일관성이 개선되었습니다.

@seueooo seueooo self-assigned this Aug 22, 2025
@seueooo seueooo requested a review from seung365 as a code owner August 22, 2025 13:27
@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
time-capsule Ready Ready Preview Comment Aug 22, 2025 1:27pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 22, 2025

Walkthrough

useLogout 성공 핸들러에 userInfo 쿼리 무효화가 추가되었습니다. 이를 위해 shared의 userQueryKeys가 export되어 외부에서 참조 가능해졌습니다. 그 외 공개 API 시그니처 변화는 userQueryKeys의 export 추가뿐입니다.

Changes

Cohort / File(s) Summary
Auth API 훅 갱신
app/(auth)/_api/auth.queries.ts
userQueryKeys를 임포트하고, useLogoutonSuccess에서 queryClient.clear() 이후 queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() }) 호출 추가
쿼리 키 공개
shared/api/queries/user.ts
userQueryKeysexport const로 변경하여 외부 모듈에서 사용 가능하게 함. 객체 구조와 반환 값은 동일

Sequence Diagram(s)

sequenceDiagram
  actor U as User
  participant C as Component/useLogout
  participant S as Logout API
  participant Q as QueryClient

  U->>C: Trigger logout()
  C->>S: call logout mutation
  S-->>C: onSuccess
  rect rgba(200,235,255,0.3)
    note right of C: 변경됨
    C->>Q: clear()
    C->>Q: invalidateQueries({ queryKey: userQueryKeys.userInfo() })
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@seueooo seueooo changed the title Fix: 로그아웃시 유저 정보 쿼리키 무효화 Fix: 로그아웃시 로그인 페이지로 이동 Aug 22, 2025
@github-actions
Copy link
Copy Markdown

This pull request (commit afca296) has been deployed to Vercel ▲ - View GitHub Actions Workflow Logs

Name Link
🌐 Unique https://time-capsule-fm87j61jr-hs-projects-b4a69d5f.vercel.app
🔍 Inspect https://vercel.com/hs-projects-b4a69d5f/time-capsule/5uRrK1KpngPBq1TxvAbUVckaqinw

@github-actions
Copy link
Copy Markdown

🚀 Storybook 배포

📖 Storybook: https://683d91ab23651aa0b399e435-jzdsemfqcd.chromatic.com/
🔗 Chromatic Build: https://www.chromatic.com/build?appId=683d91ab23651aa0b399e435&number=221
✅ Status: success

@seueooo seueooo closed this Aug 22, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
shared/api/queries/user.ts (1)

6-9: userQueryKeys export은 적절합니다. 반환 키를 튜플로 고정해 타입 안정성 강화 제안

현재 as const는 객체 프로퍼티에만 영향을 주고, 함수 반환값 배열은 여전히 string[]로 추론됩니다. React Query v5의 QueryKey(readonly unknown[])와도 호환되지만, 키 타이핑을 더 견고하게 만들기 위해 반환 배열도 튜플로 고정하는 것을 권장합니다. 향후 키 변경 시 컴파일 타임에서 더 빨리 깨집니다.

 export const userQueryKeys = {
-  all: () => ["user"],
-  userInfo: () => [...userQueryKeys.all(), "userInfo"],
+  all: () => ["user"] as const,
+  userInfo: () => [...userQueryKeys.all(), "userInfo"] as const,
 } as const;
+export type UserQueryKey = ReturnType<typeof userQueryKeys.userInfo>;
app/(auth)/_api/auth.queries.ts (2)

21-22: clear 이후 invalidate는 실익이 없습니다

clear()로 캐시를 지운 직후 동일 키를 invalidate해도 타겟 쿼리가 없어 no-op에 가깝습니다. 위 코멘트대로 취소/제거로 대체하거나, clear()만 쓰는 전략으로 단순화하세요.


22-22: 특정 키보다 루트 키로 범위 지정 권장

확장성을 위해 userInfo()가 아닌 userQueryKeys.all() 기준으로 무효화/제거/취소를 수행하면 향후 user 하위 키가 늘어나도 변경이 최소화됩니다.

- queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() });
+ queryClient.invalidateQueries({ queryKey: userQueryKeys.all() });
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b0c7f15 and afca296.

📒 Files selected for processing (2)
  • app/(auth)/_api/auth.queries.ts (2 hunks)
  • shared/api/queries/user.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/(auth)/_api/auth.queries.ts (1)
shared/api/queries/user.ts (1)
  • userQueryKeys (6-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: storybook-deploy
  • GitHub Check: test
  • GitHub Check: deploy

Comment on lines 20 to 23
onSuccess: () => {
queryClient.clear();
queryClient.invalidateQueries({ queryKey: userQueryKeys.userInfo() });
},
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant