Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 인증코드 검증 및 회원가입 토큰 발급 로직 작성 #16

Merged
merged 4 commits into from
Sep 29, 2024

Conversation

waterfogSW
Copy link
Member

@waterfogSW waterfogSW commented Sep 29, 2024

Summary by CodeRabbit

  • New Features

    • 인증 코드 검증 기능 추가: 사용자가 인증 코드를 검증할 수 있는 새로운 메소드가 추가되었습니다.
    • 새로운 tokenSecret 속성 추가: 인증 구성 옵션이 확장되었습니다.
    • 등록 토큰 생성 및 검증 기능 추가: JWT를 사용하여 등록 토큰을 생성하고 검증하는 기능이 도입되었습니다.
  • Bug Fixes

    • 인증 코드가 존재하지 않을 경우 NotFoundException을 발생시키는 기능 추가: 오류 처리 개선.
  • Tests

    • 인증 코드 검증을 위한 테스트 케이스 추가: 유효한 코드, 만료된 코드, 잘못된 코드에 대한 테스트가 포함되었습니다.

Copy link

coderabbitai bot commented Sep 29, 2024

Walkthrough

이 변경 사항은 인증 프로세스를 개선하기 위해 여러 파일에서 새로운 기능과 속성을 추가합니다. AuthProperties.kt 파일에 tokenSecret 속성이 추가되어 인증 구성 옵션이 확장되었으며, CommandAuthCode.kt 인터페이스에 인증 코드 검증을 위한 verify 메서드가 도입되었습니다. 이와 함께 AuthCodeService.kt에서 검증 로직이 구현되고, 새로운 RegisterToken 클래스가 추가되어 JWT 기반의 등록 토큰 생성 및 검증 기능이 포함되었습니다.

Changes

파일 경로 변경 요약
application/src/main/kotlin/com/threedays/application/auth/config/AuthProperties.kt AuthProperties 데이터 클래스에 tokenSecret 속성 추가.
application/src/main/kotlin/com/threedays/application/auth/port/inbound/CommandAuthCode.kt CommandAuthCode 인터페이스에 verify 메서드 추가.
application/src/main/kotlin/com/threedays/application/auth/service/AuthCodeService.kt AuthCodeService 클래스에 verify 메서드 추가 및 인증 코드 검증 로직 구현.
application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt AuthCodeCommandVerify 데이터 클래스 추가, 인증 코드 ID와 코드를 포함.
application/src/main/resources/application-application.yaml auth 섹션에 token-secret 구성 항목 추가.
application/src/test/kotlin/com/threedays/application/auth/service/AuthCodeServiceTest.kt 인증 코드 검증을 위한 테스트 케이스 추가 및 테스트 구조 개선.
domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthToken.kt AuthToken 인터페이스 추가, 인증 토큰의 문자열 표현을 위한 계약 정의.
domain/src/main/kotlin/com/threedays/domain/auth/entity/RegisterToken.kt RegisterToken 데이터 클래스 추가, JWT 기반의 등록 토큰 생성 및 검증 기능 구현.
domain/src/main/kotlin/com/threedays/domain/auth/exception/AuthException.kt RegisterTokenExpiredExceptionInvalidRegisterTokenException 데이터 클래스 추가.
domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt get(id: AuthCodeId) 메서드 추가, 인증 코드 검색 시 오류 처리 구현.
domain/src/test/kotlin/com/threedays/domain/auth/entity/RegisterTokenTest.kt RegisterToken 클래스에 대한 단위 테스트 추가, 생성 및 검증 기능 테스트.
support/common/src/main/kotlin/com/threedays/support/common/exception/NotFoundException.kt NotFoundException 클래스 추가, 요청된 리소스가 없을 때 발생하는 사용자 정의 예외.

Possibly related PRs

Suggested reviewers

  • dojinyou

🐰 새로운 토큰의 비밀을 담아
인증의 길을 밝혀줄 거야.
코드가 검증되면 기쁨이 넘쳐,
등록의 순간을 기다리며,
우리 모두 함께 해보자,
안전한 세상을 위해 뛰어보자! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 resolve resolve all the CodeRabbit review comments.
  • @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

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: 8

🧹 Outside diff range and nitpick comments (8)
domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthToken.kt (2)

1-7: 간단하고 명확한 인터페이스 구조입니다.

이 인터페이스는 인증 토큰을 위한 간단한 계약을 제공합니다. 다양한 인증 토큰 구현을 허용하면서도 일관된 인터페이스를 유지할 수 있게 해줍니다.

인터페이스의 목적을 설명하는 간단한 문서 주석을 추가하는 것이 좋을 것 같습니다. 예를 들어:

/**
 * 인증 토큰을 나타내는 인터페이스입니다.
 * 이 인터페이스를 구현하는 클래스는 문자열 형태의 토큰 값을 제공해야 합니다.
 */
interface AuthToken {
    // ... existing code ...
}

5-5: value 속성이 명확하게 정의되어 있습니다.

value 속성은 간단하고 직관적입니다. 하지만 더 구체적인 이름을 사용하면 코드의 가독성을 높일 수 있습니다.

속성 이름을 더 구체적으로 변경하는 것을 고려해보세요. 예를 들어:

val tokenValue: String

또는

val rawToken: String

이렇게 하면 속성의 목적이 더 명확해질 수 있습니다.

support/common/src/main/kotlin/com/threedays/support/common/exception/NotFoundException.kt (1)

1-3: 구현이 올바르며 개선 제안

전반적인 구현은 정확하고 간결합니다. 다음과 같은 개선 사항을 고려해 보시기 바랍니다:

  1. 클래스에 KDoc 주석을 추가하여 이 예외의 사용 시기와 방법을 설명합니다.
  2. 이 클래스를 상속할 가능성이 있다면 open 키워드를 추가하는 것을 고려해 보세요.
  3. 더 자세한 오류 보고를 위해 Throwable 원인 매개변수를 받는 보조 생성자를 추가할 수 있습니다.

다음과 같이 코드를 개선할 수 있습니다:

package com.threedays.support.common.exception

/**
 * 요청된 리소스를 찾을 수 없을 때 발생하는 예외입니다.
 *
 * @param message 예외에 대한 상세 메시지
 * @param cause 이 예외의 원인 (선택적)
 */
open class NotFoundException : RuntimeException {
    constructor(message: String) : super(message)
    constructor(message: String, cause: Throwable) : super(message, cause)
}
application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt (1)

15-15: 스타일 개선: 후행 쉼표 제거 고려

코드의 일관성을 위해 code 속성 뒤의 후행 쉼표를 제거하는 것이 좋습니다.

다음과 같이 수정하는 것을 고려해보세요:

 data class Verify(
     val id: AuthCodeId,
-    val code: String,
+    val code: String
 )
domain/src/main/kotlin/com/threedays/domain/auth/exception/AuthException.kt (3)

18-20: LGTM! 약간의 개선 제안

RegisterTokenExpiredException 클래스가 잘 구현되었습니다. 에러 코드와 메시지가 일관성 있게 작성되었습니다.

가독성을 높이기 위해 다음과 같이 메시지를 상수로 추출하는 것을 고려해 보세요:

companion object {
    private const val REGISTER_TOKEN_EXPIRED_MESSAGE = "회원 가입 토큰이 만료되었습니다."
}

data class RegisterTokenExpiredException(
    override val message: String = REGISTER_TOKEN_EXPIRED_MESSAGE
) : AuthException(1003, message)

이렇게 하면 메시지를 쉽게 재사용하고 관리할 수 있습니다.


22-24: LGTM! 약간의 개선 제안

InvalidRegisterTokenException 클래스가 잘 구현되었습니다. 에러 코드와 메시지가 일관성 있게 작성되었습니다.

가독성을 높이기 위해 다음과 같이 메시지를 상수로 추출하는 것을 고려해 보세요:

companion object {
    private const val INVALID_REGISTER_TOKEN_MESSAGE = "유효하지 않은 회원 가입 토큰입니다."
}

data class InvalidRegisterTokenException(
    override val message: String = INVALID_REGISTER_TOKEN_MESSAGE
) : AuthException(1004, message)

이렇게 하면 메시지를 쉽게 재사용하고 관리할 수 있습니다.


18-24: 문서 업데이트 제안

새로운 예외 클래스 RegisterTokenExpiredExceptionInvalidRegisterTokenException이 잘 구현되었습니다. 이러한 변경사항을 반영하기 위해 다음 작업을 고려해 보세요:

  1. 프로젝트의 예외 처리 가이드 또는 문서를 업데이트하여 이 새로운 예외들에 대한 설명을 추가합니다.
  2. 이 예외들을 사용하는 개발자들을 위한 사용 예시를 추가합니다.
  3. 필요한 경우, 관련된 테스트 케이스를 업데이트하거나 추가합니다.

이렇게 하면 팀원들이 새로운 예외들을 더 쉽게 이해하고 올바르게 사용할 수 있을 것입니다.

application/src/test/kotlin/com/threedays/application/auth/service/AuthCodeServiceTest.kt (1)

71-72: 테스트 코드에서 반복되는 전화번호 상수화 제안

테스트 케이스마다 "01012345678"을 반복적으로 사용하고 있습니다. 해당 값을 상수로 선언하여 중복을 줄이고 코드의 유지보수성을 향상시키는 것을 권장합니다.

적용 가능한 변경 사항 예시:

+    // 상단에 상수 선언
+    val testPhoneNumber = "01012345678"

     // 각 테스트 케이스에서 수정
-    phoneNumber = "01012345678",
+    phoneNumber = testPhoneNumber,

Also applies to: 99-101, 120-122

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ad20b53 and ac06036.

📒 Files selected for processing (12)
  • application/src/main/kotlin/com/threedays/application/auth/config/AuthProperties.kt (1 hunks)
  • application/src/main/kotlin/com/threedays/application/auth/port/inbound/CommandAuthCode.kt (1 hunks)
  • application/src/main/kotlin/com/threedays/application/auth/service/AuthCodeService.kt (2 hunks)
  • application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt (2 hunks)
  • application/src/main/resources/application-application.yaml (1 hunks)
  • application/src/test/kotlin/com/threedays/application/auth/service/AuthCodeServiceTest.kt (3 hunks)
  • domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthToken.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/auth/entity/RegisterToken.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/auth/exception/AuthException.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt (1 hunks)
  • domain/src/test/kotlin/com/threedays/domain/auth/entity/RegisterTokenTest.kt (1 hunks)
  • support/common/src/main/kotlin/com/threedays/support/common/exception/NotFoundException.kt (1 hunks)
🔇 Additional comments (14)
application/src/main/kotlin/com/threedays/application/auth/config/AuthProperties.kt (2)

7-8: 변경 사항이 적절해 보입니다.

tokenSecret 속성이 추가되어 인증 관련 구성 옵션이 확장되었습니다. 이는 JWT 토큰 서명이나 암호화에 사용될 것으로 보입니다.


8-8: 토큰 비밀의 안전한 처리를 확인하세요.

tokenSecret과 같은 민감한 정보를 구성 속성으로 저장할 때는 보안에 주의해야 합니다. 다음 사항을 고려해 주세요:

  1. 프로덕션 환경에서는 환경 변수나 안전한 비밀 관리 시스템을 통해 이 값을 제공하세요.
  2. 로그나 오류 메시지에 이 값이 노출되지 않도록 주의하세요.
  3. 애플리케이션 내에서 이 값에 대한 접근을 제한하고, 필요한 경우에만 사용하세요.

다음 스크립트를 실행하여 tokenSecret이 안전하게 처리되고 있는지 확인하세요:

application/src/main/kotlin/com/threedays/application/auth/port/inbound/CommandAuthCode.kt (2)

5-5: LGTM: 새로운 import 문이 올바르게 추가되었습니다.

RegisterToken에 대한 import 문이 적절하게 추가되었으며, 기존의 도메인 계층 import 패턴을 따르고 있습니다.


10-10: LGTM: 새로운 메서드가 적절하게 추가되었습니다. 구현 클래스 확인 필요.

verify 메서드가 인터페이스에 잘 추가되었습니다. 메서드 이름과 파라미터 타입이 명확하고 일관성 있게 작성되었습니다.

다만, 이 변경으로 인해 CommandAuthCode 인터페이스를 구현하는 모든 클래스들이 영향을 받을 수 있습니다. 다음 스크립트를 실행하여 영향을 받는 구현 클래스들을 확인해 주세요:

이 스크립트의 결과를 바탕으로 필요한 구현 클래스들을 업데이트했는지 확인해 주세요.

✅ Verification successful

검증 완료: verify 메서드가 모든 구현 클래스에 적절히 추가되었습니다.

  • AuthCodeService.ktCommandAuthCode.kt 파일에서 verify 메서드가 올바르게 구현되었습니다.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find classes implementing CommandAuthCode interface

echo "Classes implementing CommandAuthCode:"
rg --type kotlin -l "class .+ : CommandAuthCode"

echo "\nClasses implementing CommandAuthCode that might need updates:"
rg --type kotlin -l "class .+ : CommandAuthCode" | xargs rg -L "fun verify\("

Length of output: 856

application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt (1)

13-16: LGTM: Verify 클래스 추가가 적절합니다.

새로운 Verify 데이터 클래스의 추가는 AuthCodeCommand의 기능을 확장하는 데 적절해 보입니다. 속성들이 논리적으로 올바르며 Kotlin의 데이터 클래스 규칙을 잘 따르고 있습니다.

domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt (2)

6-6: 새로운 import 문이 올바르게 추가되었습니다.

NotFoundException을 위한 import 문이 적절하게 추가되었습니다. 이는 새로 추가된 메서드에서 사용되는 예외를 처리하기 위해 필요합니다.


10-10: 새로운 get 메서드가 잘 구현되었습니다. NotFoundException에 대한 추가 정보가 필요합니다.

새로 추가된 get 메서드는 간결하고 효과적으로 구현되었습니다. Kotlin의 null-safe 호출 연산자와 Elvis 연산자를 잘 활용하고 있습니다.

하나의 질문이 있습니다:

  • NotFoundException이 커스텀 예외인지, 아니면 표준 라이브러리의 일부인지 확인해 주실 수 있나요? 만약 커스텀 예외라면, 이 예외 클래스에 대한 문서나 간단한 설명을 추가하는 것이 도움이 될 것 같습니다.

다음 스크립트를 실행하여 NotFoundException의 출처를 확인해 보겠습니다:

✅ Verification successful

get 메서드 변경 사항 승인 및 NotFoundException 확인됨

NotFoundException은 커스텀 예외로 정의되어 있습니다. 해당 예외에 대한 설명이나 문서를 추가하면 코드의 가독성을 높이는 데 도움이 될 것 같습니다.

  • NotFoundException 클래스는 support/common/src/main/kotlin/com/threedays/support/common/exception/NotFoundException.kt에 위치하고 있습니다.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the source of NotFoundException

# Test: Search for the NotFoundException class definition
rg --type kotlin -g '!**/build/**' 'class NotFoundException'

Length of output: 222

domain/src/main/kotlin/com/threedays/domain/auth/entity/RegisterToken.kt (1)

1-16: 코드 품질 우수

코드가 명확하며, 함수와 예외 처리가 적절하게 구현되어 있습니다. 전체적으로 특별한 문제점이 발견되지 않았습니다.

Also applies to: 27-47, 51-56

application/src/test/kotlin/com/threedays/application/auth/service/AuthCodeServiceTest.kt (6)

11-17: 필요한 라이브러리 Import 추가 확인

추가된 Import 문들이 테스트에 필요한 라이브러리들을 정확히 가져오고 있습니다.


23-23: 테스트 클래스에 DisplayName 어노테이션 추가

테스트 클래스에 @DisplayName 어노테이션을 추가하여 가독성을 높인 점이 좋습니다.


30-31: 유효기간 변수를 도입하여 코드 가독성 향상

expirationSeconds 변수를 도입하여 코드의 가독성과 유지보수성을 높인 점이 좋습니다.


66-93: 인증 코드 검증 테스트 케이스 추가

유효한 인증 코드에 대한 테스트 케이스를 추가하여 정상 동작을 확인하신 점이 좋습니다. 토큰 검증까지 포함하여 로직의 완전성을 높였습니다.


95-114: 만료된 인증 코드에 대한 예외 처리 테스트

만료된 인증 코드 사용 시 올바른 예외가 발생하는지 테스트하여 예외 처리가 정확히 이루어짐을 검증하셨습니다.


116-135: 유효하지 않은 인증 코드에 대한 예외 처리 테스트

잘못된 인증 코드 입력 시 적절한 예외가 발생하는지 테스트하여 서비스의 안전성을 높이셨습니다.

@waterfogSW waterfogSW merged commit 3a55ebe into main Sep 29, 2024
3 checks passed
@waterfogSW waterfogSW deleted the feat branch September 29, 2024 01:43
waterfogSW added a commit that referenced this pull request Sep 29, 2024
* 🩹 리뷰 반영

* 🩹 리뷰 반영

* ✨ 인증코드 검증 및 회원가입 토큰 발급 로직 작성
@waterfogSW waterfogSW self-assigned this Oct 3, 2024
@waterfogSW waterfogSW changed the title Feat ✨ 인증코드 검증 및 회원가입 토큰 발급 로직 작성 Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant