Skip to content

Feat: 로그아웃 구현 [JDDESIGN-7]#80

Open
yiyoonseo wants to merge 1 commit into
developfrom
feature/JDDESIGN-7-logout-feat
Open

Feat: 로그아웃 구현 [JDDESIGN-7]#80
yiyoonseo wants to merge 1 commit into
developfrom
feature/JDDESIGN-7-logout-feat

Conversation

@yiyoonseo

@yiyoonseo yiyoonseo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🔗 관련 이슈

JDDESIGN-7

  • Close #

📝 개요

  • 로그아웃 로직 구현

⌨️ 작업 상세 내용

  • 기존 postAuth 유틸리티를 활용한 서버 로그아웃 API(requestLogout) 함수 구현
  • 클라이언트 토큰(로컬 스토리지, 쿠키) 삭제 로직(clearAuthTokens) 적용
  • Lnb 컴포넌트 내 로그아웃 버튼에 handleLogout 핸들러 연결
  • 로그아웃 완료 및 에러 발생 시 로그인 페이지(/login)로 리다이렉트 처리

💡 코드 설명 및 참고사항

기존에 구축되어 있던 postAuth와 clearAuthTokens를 재사용하여 중복 코드를 줄이고 일관성을 유지했습니다.

예외 처리 정책: 서버의 로그아웃 API 호출이 실패(에러)하더라도, 클라이언트 측의 만료된 토큰 찌꺼기가 남지 않도록 무조건 clearAuthTokens()를 호출하여 토큰을 비우고 로그인 페이지로 보내도록 구현했습니다.

📸 스크린샷 (UI 변경 시)

🔍 리뷰 요구사항 (Reviewers)

  • [ ]

⚠️ 로컬 실행 시 유의사항

Summary by CodeRabbit

  • New Features
    • Added a logout button to the navigation sidebar for convenient account sign-out
    • Enhanced text button styling with configurable hover effect options

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a logout capability: a requestLogout API function is added to auth.ts, TextButton gains a configurable hover prop with "textOnly" | "none" variants, and the Lnb sidebar integrates a handleLogout handler and a "로그아웃" button that clears tokens and redirects to /login.

Changes

Logout Feature with TextButton Hover

Layer / File(s) Summary
Logout API and TextButton hover prop
jobdri/src/lib/auth.ts, jobdri/src/components/common/buttons/TextButton.tsx
Adds LogoutRequest type and requestLogout(accessToken, refreshToken) that POSTs to /api/auth/logout. Exports HoverType ("textOnly" | "none") and TextButtonIconPosition, extends TextButtonProps with optional hover, and updates the button's className to conditionally apply hover-background or hover-text-transparent styles.
Lnb logout handler and UI
jobdri/src/components/common/lnb/Lnb.tsx
Imports auth utilities and TextButton. Adds handleLogout async handler reading tokens from localStorage, calling requestLogout, clearing tokens via clearAuthTokens, and redirecting to /login. Renders the "로그아웃" TextButton with hover="textOnly" in the sidebar footer.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, a button appears,
To log you out, no need for tears!
Tokens cleared, the path reset,
Back to /login—no regret.
The sidebar shines with one new link,
A rabbit coded it, quick as a wink! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: implementing logout functionality with a reference to the ticket (JDDESIGN-7).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/JDDESIGN-7-logout-feat

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e70ed7 and 8d0f19e.

📒 Files selected for processing (3)
  • jobdri/src/components/common/buttons/TextButton.tsx
  • jobdri/src/components/common/lnb/Lnb.tsx
  • jobdri/src/lib/auth.ts

Comment on lines +109 to +127
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");
};

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 | 🟡 Minor | ⚡ Quick win

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.

@minnngo minnngo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

수고많았어~~👍👍

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.

2 participants