Skip to content

Conversation

@efdao
Copy link
Collaborator

@efdao efdao commented Mar 26, 2025

#️⃣ 연관된 이슈>

📝 작업 내용> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

  • CookieUtil에 MaxAge를 0으로 Cookie 생성하는 메서드 추가했습니다.
  • 만들어진 쿠키를 AuthService에서 set-cookie로 응답 헤더에 추가합니다.
  • 리프레시 토큰 무효화 관련 처리는 RTR(Refresh Token Rotation) 작업 시 추가할 예정입니다.

🙏 여기는 꼭 봐주세요! > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

Summary by CodeRabbit

  • New Features
    • Introduced a secure logout option that now invalidates the refresh token by deleting the associated cookie, enhancing user session security.

@efdao efdao added the 🛠️ BE Backend label Mar 26, 2025
@efdao efdao added this to the 💪8차 스프린트 milestone Mar 26, 2025
@efdao efdao self-assigned this Mar 26, 2025
@efdao efdao requested a review from kwon204 as a code owner March 26, 2025 05:11
@efdao efdao linked an issue Mar 26, 2025 that may be closed by this pull request
2 tasks
@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2025

Walkthrough

This pull request adds logout functionality to the backend authentication flow. A new logout method is introduced in the AuthController, which maps a POST request to /api/v1/logout and calls the corresponding method in AuthService. In turn, AuthService invalidates the refresh token by invoking a new cookie deletion method in CookieUtil. A minor formatting adjustment was also made in the refresh method.

Changes

File(s) Summary
backend/.../AuthController.java, backend/.../AuthService.java Added new logout methods. The controller maps POST /api/v1/logout to a service call that invalidates the refresh token. A minor formatting tweak was applied.
backend/.../CookieUtil.java Added deleteRefreshTokenCookie method to create a cookie with a null value, set to expire immediately, effectively deleting the refresh token cookie.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant AC as AuthController
    participant AS as AuthService
    participant CU as CookieUtil

    C->>AC: POST /api/v1/logout
    AC->>AS: logout(response)
    AS->>CU: deleteRefreshTokenCookie()
    CU-->>AS: Cookie object
    AS-->>AC: void
    AC-->>C: ResponseEntity (No Content)
Loading

Possibly related PRs

Suggested reviewers

  • kwon204

Poem

In my burrow of code I happily roam,
Adding logout features to make sessions at home,
Refresh tokens vanish like shadows at noon,
Cookies deleted with a swift, clever tune,
My hops dance in lines of pure delight,
A rabbit’s joy coding under the moon!
🐰💻

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

Copy link

@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: 0

🧹 Nitpick comments (3)
backend/src/main/java/endolphin/backend/global/util/CookieUtil.java (1)

38-45: Well-implemented deleteRefreshTokenCookie method

The implementation correctly handles cookie deletion by setting its value to null and MaxAge to 0, which instructs browsers to immediately remove the cookie. The method also maintains consistency with the existing cookie creation by reusing the same security properties.

Consider adding JavaDoc to document the purpose and behavior of this method:

+    /**
+     * Creates a cookie configured to delete the refresh token from the client.
+     * Sets value to null and MaxAge to 0 to ensure immediate deletion by the browser.
+     * 
+     * @return Cookie configured to delete the refresh token
+     */
     public Cookie deleteRefreshTokenCookie() {
         Cookie refreshTokenCookie = new Cookie(properties.name(), null);
         refreshTokenCookie.setHttpOnly(properties.httpOnly());
         refreshTokenCookie.setSecure(properties.secure());
         refreshTokenCookie.setPath(properties.path());
         refreshTokenCookie.setMaxAge(0);
         return refreshTokenCookie;
     }
backend/src/main/java/endolphin/backend/domain/auth/AuthService.java (1)

77-80: Logout implementation looks good

The implementation effectively invalidates the refresh token cookie by adding a cookie with MaxAge=0 to the response.

Consider enhancing the TODO comment with more specific information about the planned implementation:

     public void logout(HttpServletResponse response) {
         response.addCookie(cookieUtil.deleteRefreshTokenCookie());
-        //TODO: refresh token 무효 처리
+        //TODO: Implement refresh token invalidation as part of Refresh Token Rotation (RTR) - Issue #XXX
     }
backend/src/main/java/endolphin/backend/domain/auth/AuthController.java (1)

7-7: Remove unused import

The ApiResponses import is not being used in the class.

-import io.swagger.v3.oas.annotations.responses.ApiResponses;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f24b1a and cce2669.

📒 Files selected for processing (3)
  • backend/src/main/java/endolphin/backend/domain/auth/AuthController.java (2 hunks)
  • backend/src/main/java/endolphin/backend/domain/auth/AuthService.java (3 hunks)
  • backend/src/main/java/endolphin/backend/global/util/CookieUtil.java (1 hunks)
🔇 Additional comments (2)
backend/src/main/java/endolphin/backend/domain/auth/AuthService.java (1)

61-61: Formatting improvement

Good spacing improvement for better readability.

backend/src/main/java/endolphin/backend/domain/auth/AuthController.java (1)

73-78: Well-implemented logout endpoint

The logout endpoint is appropriately implemented as a POST request with proper documentation and correct response handling. The method returns 204 No Content status which is appropriate for this operation.

Copy link
Contributor

@kwon204 kwon204 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

@efdao efdao merged commit a81d7d8 into dev Mar 26, 2025
7 checks passed
@efdao efdao deleted the feature/be/logout branch March 26, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ BE Backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 로그아웃 api 구현

3 participants