Feat: 로그아웃 구현 [JDDESIGN-7]#80
Conversation
📝 WalkthroughWalkthroughAdds a logout capability: a ChangesLogout Feature with TextButton Hover
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@jobdri/src/components/common/lnb/Lnb.tsx`:
- Around line 109-127: The handleLogout function retrieves tokens from
localStorage which can throw errors in restricted-storage environments, causing
the cleanup and navigation logic at the end (clearAuthTokens and router.replace
calls) to be skipped. Refactor the handleLogout function to wrap the entire
logout flow in a try/finally block, moving the clearAuthTokens and
router.replace("/login") calls into the finally block to ensure they always
execute regardless of any errors thrown during token retrieval or the
requestLogout call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1f9c1279-d1cf-43f6-af61-4011b1a8d77a
📒 Files selected for processing (3)
jobdri/src/components/common/buttons/TextButton.tsxjobdri/src/components/common/lnb/Lnb.tsxjobdri/src/lib/auth.ts
| const handleLogout = async () => { | ||
| const accessToken = window.localStorage.getItem( | ||
| AUTH_STORAGE_KEYS.accessToken, | ||
| ); | ||
| const refreshToken = window.localStorage.getItem( | ||
| AUTH_STORAGE_KEYS.refreshToken, | ||
| ); | ||
|
|
||
| if (accessToken && refreshToken) { | ||
| try { | ||
| await requestLogout(accessToken, refreshToken); | ||
| } catch (error) { | ||
| console.error("서버 로그아웃 처리 실패:", error); | ||
| } | ||
| } | ||
|
|
||
| clearAuthTokens(); | ||
| router.replace("/login"); | ||
| }; |
There was a problem hiding this comment.
Wrap logout flow in try/finally to guarantee cleanup/navigation.
At Line 110 and Line 113, localStorage.getItem can throw in restricted-storage environments. If that happens, clearAuthTokens() and router.replace("/login") at Line 125-126 are skipped. Move cleanup/redirect to finally.
Suggested patch
- const handleLogout = async () => {
- const accessToken = window.localStorage.getItem(
- AUTH_STORAGE_KEYS.accessToken,
- );
- const refreshToken = window.localStorage.getItem(
- AUTH_STORAGE_KEYS.refreshToken,
- );
-
- if (accessToken && refreshToken) {
- try {
- await requestLogout(accessToken, refreshToken);
- } catch (error) {
- console.error("서버 로그아웃 처리 실패:", error);
- }
- }
-
- clearAuthTokens();
- router.replace("/login");
- };
+ const handleLogout = async () => {
+ try {
+ const accessToken = window.localStorage.getItem(
+ AUTH_STORAGE_KEYS.accessToken,
+ );
+ const refreshToken = window.localStorage.getItem(
+ AUTH_STORAGE_KEYS.refreshToken,
+ );
+
+ if (accessToken && refreshToken) {
+ try {
+ await requestLogout(accessToken, refreshToken);
+ } catch (error) {
+ console.error("서버 로그아웃 처리 실패:", error);
+ }
+ }
+ } finally {
+ clearAuthTokens();
+ router.replace("/login");
+ }
+ };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@jobdri/src/components/common/lnb/Lnb.tsx` around lines 109 - 127, The
handleLogout function retrieves tokens from localStorage which can throw errors
in restricted-storage environments, causing the cleanup and navigation logic at
the end (clearAuthTokens and router.replace calls) to be skipped. Refactor the
handleLogout function to wrap the entire logout flow in a try/finally block,
moving the clearAuthTokens and router.replace("/login") calls into the finally
block to ensure they always execute regardless of any errors thrown during token
retrieval or the requestLogout call.
🔗 관련 이슈
JDDESIGN-7
📝 개요
⌨️ 작업 상세 내용
💡 코드 설명 및 참고사항
예외 처리 정책: 서버의 로그아웃 API 호출이 실패(에러)하더라도, 클라이언트 측의 만료된 토큰 찌꺼기가 남지 않도록 무조건 clearAuthTokens()를 호출하여 토큰을 비우고 로그인 페이지로 보내도록 구현했습니다.
📸 스크린샷 (UI 변경 시)
🔍 리뷰 요구사항 (Reviewers)
Summary by CodeRabbit