-
Notifications
You must be signed in to change notification settings - Fork 1
fix: 로그인 로직 수정 완료 #15
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
Conversation
- 간혹, 스웨거 명세에 dto 네이밍이 클래스 이름과 동일하게 들어가지 않는 문제를 해결하기 위해 직접 명세함.
…r 타입 안전한 파싱 방식으로 변경 - 기존 extractField 메서드를 통한 수동 문자열 파싱 방식을 제거 - Jackson ObjectMapper를 활용한 표준 JSON 파싱으로 대체 - 타입 안전성 확보를 위해 as? 연산자를 사용한 null-safe 캐스팅 적용
- try-catch 방식을 runCatching/recoverCatching으로 변경하여 함수형 스타일 적용 - 타입별 예외 처리 로직 추가: RestClientException 등 구체적 예외 변환 - Jackson @JsonProperty 어노테이션으로 snake_case API 응답을 camelCase로 매핑
- Result를 반환하는건 예외 처리를 호출자에게 위임하는 것임. - 하지만 usecase는 단순 로직들의 흐름도를 나타내기에 예외 처리를 usecase에게 위임하는것은 맞지 않다고 판단함.
📝 Walkthrough## Walkthrough
이번 변경은 인증 및 사용자 관리 로직의 대규모 리팩토링과 오류 수정에 초점을 맞췄습니다. 소셜 로그인, 토큰 관리, 예외 처리, 도메인-인프라 계층 분리, Feign 기반 외부 API 연동, 소프트 삭제 등 인증 전반에 걸친 구조 개선과 미세한 오류 수정이 포함됩니다.
## Changes
| 파일/경로 그룹 | 변경 요약 |
|---|---|
| apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthController.kt, AuthControllerApi.kt | Spring MVC 어노테이션 명시적 추가, 파라미터 바인딩 및 반환 타입 명확화, API 문서화 설명 보강, signOut 반환 타입 변경 |
| apis/src/main/kotlin/org/yapp/apis/auth/dto/request/*.kt, response/*.kt | DTO에 OpenAPI 어노테이션 추가, 필드 nullable 처리, 검증 헬퍼 메서드 추가, 예외 처리 강화 |
| apis/src/main/kotlin/org/yapp/apis/auth/strategy/*.kt | 인증 전략별 리팩토링: Apple/Kakao 인증 로직 외부 helper로 위임, 반환 타입 User→UserCreateInfo, 예외 처리 일원화 |
| apis/src/main/kotlin/org/yapp/apis/auth/service/*.kt, usecase/AuthUseCase.kt | UserAuthService 신규 도입, 토큰/유저 서비스 의존성 변경, 토큰 관리 로직 helper로 위임, 도메인 서비스 분리 |
| apis/src/main/kotlin/org/yapp/apis/auth/helper/*.kt | AppleJwtHelper, KakaoApiHelper, AuthTokenHelper 등 helper 컴포넌트 신규 도입, 외부 API 및 토큰 관리 추상화 |
| domain/src/main/kotlin/org/yapp/domain/user/User.kt, vo/SocialUserProfile.kt | User 생성자 private화, soft delete 필드 추가, 생성/복원 팩토리 메서드 도입, SocialUserProfile 신규 도입 및 검증 강화 |
| domain/src/main/kotlin/org/yapp/domain/service/domain/UserDomainService.kt, redis/TokenDomainRedisService.kt | 도메인 서비스 신규 도입, 사용자/토큰 관리 기능 세분화 및 soft delete/restore 지원 |
| domain/src/main/kotlin/org/yapp/domain/token/*.kt | RefreshToken, RefreshTokenRepository 신규 도입, 토큰 관리 인터페이스 및 엔티티 분리 |
| infra/src/main/kotlin/org/yapp/infra/* | JPA/Redis/Feign 설정 클래스 및 리포지토리/엔티티/어댑터 신규 도입, 패키지 구조 정비, 소프트 삭제, 외부 OAuth 연동 |
| global-utils/src/main/kotlin/org/yapp/globalutils/exception/*.kt, util/*.kt | 예외 처리 글로벌 핸들러 신규 도입, 시간 제공자 인터페이스 및 구현 추가, 패키지 정비 |
| build.gradle.kts, apis/build.gradle.kts, infra/build.gradle.kts, buildSrc/src/main/kotlin/Dependencies.kt | Spring Cloud BOM, OpenFeign, Validation, Kotlin Logging 등 의존성 추가 및 관리 |
| 기타 application.yml, 패키지 선언, 테스트 파일 | 패키지 선언 정비, DB 비밀번호 기본값 수정 등 환경설정 및 테스트 파일 패키지 정비 |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Client
participant AuthController
participant AuthUseCase
participant UserAuthService
participant AuthTokenHelper
participant TokenService
participant JwtTokenService
Client->>AuthController: POST /signin (소셜로그인 요청)
AuthController->>AuthUseCase: signIn(credentials)
AuthUseCase->>UserAuthService: findOrCreateUser(userInfo)
UserAuthService->>UserDomainService: find/create/restore User
UserDomainService-->>UserAuthService: User
AuthUseCase->>AuthTokenHelper: generateTokenPair(userId)
AuthTokenHelper->>JwtTokenService: generateAccessToken, generateRefreshToken
AuthTokenHelper->>TokenService: save(refreshToken)
AuthTokenHelper-->>AuthUseCase: TokenPairResponse
AuthUseCase-->>AuthController: AuthResponse
AuthController-->>Client: AuthResponse
Client->>AuthController: POST /refresh (refreshToken)
AuthController->>AuthUseCase: refreshToken(refreshToken)
AuthUseCase->>AuthTokenHelper: validateAndGetUserIdFromRefreshToken
AuthTokenHelper->>TokenService: validateRefreshTokenByTokenOrThrow
AuthTokenHelper->>TokenService: getUserIdFromToken
AuthTokenHelper->>JwtTokenService: generateAccessToken, generateRefreshToken
AuthTokenHelper->>TokenService: save(newRefreshToken)
AuthTokenHelper-->>AuthUseCase: TokenPairResponse
AuthUseCase-->>AuthController: AuthResponse
AuthController-->>Client: AuthResponseAssessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Suggested reviewers
|
There was a problem hiding this 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
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (18)
apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthController.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthControllerApi.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/request/SocialLoginRequest.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/request/TokenRefreshRequest.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/response/AuthResponse.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/response/TokenPairResponse.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/response/UserProfileResponse.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/service/TokenService.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/service/UserService.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/strategy/AppleAuthStrategy.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/strategy/AuthStrategy.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/strategy/KakaoAuthStrategy.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/usecase/AuthUseCase.kt(2 hunks)gateway/src/main/kotlin/org/yapp/gateway/jwt/JwtTokenProvider.kt(1 hunks)global-utils/build.gradle.kts(1 hunks)global-utils/src/main/kotlin/org/yapp/global/exception/CommonException.kt(1 hunks)global-utils/src/main/kotlin/org/yapp/global/exception/GlobalExceptionHandler.kt(7 hunks)infra/src/main/kotlin/org/yapp/jpa/repository/JpaUserRepository.kt(0 hunks)
💤 Files with no reviewable changes (1)
- infra/src/main/kotlin/org/yapp/jpa/repository/JpaUserRepository.kt
🔇 Additional comments (33)
global-utils/build.gradle.kts (1)
6-6: KotlinLogging 의존성 추가 승인GlobalExceptionHandler에서 구조화된 로깅을 위해 KotlinLogging 의존성을 추가한 것이 적절합니다.
apis/src/main/kotlin/org/yapp/apis/auth/strategy/AuthStrategy.kt (1)
14-14: 코드 정리 승인불필요한 공백 제거로 코드가 더 깔끔해졌습니다.
global-utils/src/main/kotlin/org/yapp/global/exception/CommonException.kt (1)
1-2: 패키지 선언 추가 승인명시적인 패키지 선언 추가로 코드 구조가 더 명확해졌습니다.
apis/src/main/kotlin/org/yapp/apis/auth/service/UserService.kt (2)
15-15: 메서드명 변경 승인 및 호출 부분 검증 필요
findById에서findUserById로의 메서드명 변경은 더 명확한 의미를 전달합니다. 하지만 이 메서드를 호출하는 모든 곳이 업데이트되었는지 확인이 필요합니다.다음 스크립트로 메서드 호출 변경을 확인하세요:
#!/bin/bash # 설명: 이전 메서드명 findById 호출이 남아있는지 확인 # 테스트: UserService의 findById 메서드 호출 검색 rg "userService\.findById" --type kotlin -A 2 -B 2 # 테스트: 새로운 메서드명 findUserById 사용 확인 rg "findUserById" --type kotlin -A 2 -B 2
1-1: ```shell
#!/bin/bash이전 메서드명 findById 호출이 남아있는지 확인
rg "findById\(" --type kotlin
변경된 메서드명 findUserById 호출이 제대로 반영되었는지 확인
rg "findUserById\(" --type kotlin -A 2 -B 2
</details> <details> <summary>global-utils/src/main/kotlin/org/yapp/global/exception/GlobalExceptionHandler.kt (3)</summary> `3-3`: **KotlinLogging 도입 승인** 구조화된 로깅을 위한 KotlinLogging 도입이 적절합니다. logger 인스턴스 생성도 올바르게 되어 있습니다. Also applies to: 18-18 --- `30-30`: **예외 핸들러 로깅 추가 승인** 각 예외 핸들러에 적절한 로깅이 추가되어 디버깅과 모니터링이 개선됩니다. 로깅 레벨(warn)도 적절합니다. Also applies to: 51-51, 70-70, 85-85 --- `96-110`: **일반 Exception 핸들러 추가 승인** 예상치 못한 예외를 처리하는 일반 Exception 핸들러 추가가 훌륭합니다. 다음 특징들이 잘 구현되었습니다: - error 레벨 로깅으로 심각한 오류 강조 - 스택 트레이스 포함으로 디버깅 지원 - 사용자에게는 민감한 정보 노출 방지 </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/service/TokenService.kt (2)</summary> `1-1`: **패키지 재구성이 적절합니다.** 인증 관련 서비스들을 `org.yapp.apis.auth.service` 패키지로 통합한 것은 코드 구조를 개선하는 좋은 변경입니다. --- `11-11`: **변수명 오타 수정이 잘 되었습니다.** `tokenDomainserviceRedis`에서 `tokenDomainRedisService`로 수정하여 카멜케이스 명명 규칙을 준수하도록 개선했습니다. 모든 참조 지점에서 일관되게 업데이트되었습니다. Also applies to: 15-15, 19-19, 23-23 </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/usecase/AuthUseCase.kt (3)</summary> `8-9`: **Import 문 업데이트가 적절합니다.** 리팩토링된 패키지 구조에 맞춰 TokenService와 UserService의 import 경로가 올바르게 업데이트되었습니다. --- `40-40`: **메서드명 변경이 더 명확합니다.** `findById`에서 `findUserById`로 변경하여 메서드의 목적이 더 명확해졌습니다. --- `45-45`: **불필요한 변환 로직 제거가 좋습니다.** `ProviderType.valueOf(user.providerType.name)` 대신 직접 `user.providerType`을 사용하여 코드가 더 간결해졌습니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthControllerApi.kt (1)</summary> `89-89`: **Kotlin 관례에 맞는 반환 타입 변경입니다.** `ResponseEntity<Void>`에서 `ResponseEntity<Unit>`으로 변경한 것은 Kotlin 코딩 관례를 따르는 좋은 개선입니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthController.kt (1)</summary> `31-31`: **인터페이스와 구현체의 일관성이 유지되었습니다.** AuthControllerApi의 변경에 맞춰 구현체도 `ResponseEntity<Unit>`으로 일관되게 업데이트되었습니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/dto/request/SocialLoginRequest.kt (2)</summary> `3-3`: **Swagger 문서화 개선을 위한 import 추가입니다.** API 문서화를 위해 필요한 Schema 어노테이션을 import했습니다. --- `12-14`: **API 문서화가 크게 개선되었습니다.** 각 필드에 대한 명확한 설명, 예시값, 필수 여부를 포함한 Swagger 어노테이션이 추가되어 API 사용성이 향상되었습니다. 특히 개발자들이 API를 이해하고 사용하기 더 쉬워졌습니다. Also applies to: 17-21, 25-29 </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/dto/request/TokenRefreshRequest.kt (1)</summary> `3-18`: **Swagger 문서화 어노테이션이 적절히 추가되었습니다.** OpenAPI 스키마 어노테이션이 클래스와 프로퍼티 레벨에서 일관되게 적용되어 API 문서의 가독성을 향상시켰습니다. 예시 값과 필수 필드 표시도 적절합니다. </details> <details> <summary>gateway/src/main/kotlin/org/yapp/gateway/jwt/JwtTokenProvider.kt (1)</summary> `75-82`: **JWT 토큰 타입 검증 로직이 개선되었습니다.** when 표현식을 사용하여 토큰의 "type" 클레임에 대한 타입 검사를 명시적으로 수행하고, null이나 잘못된 타입에 대해 구체적인 오류 메시지를 제공합니다. 이전보다 방어적이고 안전한 구현입니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/dto/response/UserProfileResponse.kt (1)</summary> `3-35`: **사용자 프로필 응답 DTO에 포괄적인 Swagger 문서화가 추가되었습니다.** 모든 프로퍼티에 대해 적절한 설명과 예시 값이 제공되어 API 문서의 완성도가 높습니다. UUID 형식, 이메일 형식, ProviderType 열거형 예시가 모두 정확합니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/dto/response/AuthResponse.kt (1)</summary> `3-31`: **인증 응답 DTO에 Swagger 문서화가 추가되고 코드 가독성이 개선되었습니다.** 토큰 필드들에 대한 명확한 설명과 현실적인 JWT 토큰 예시가 제공되었으며, companion object의 메서드 시그니처 포맷팅도 가독성을 향상시켰습니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/dto/response/TokenPairResponse.kt (1)</summary> `3-32`: **토큰 페어 응답 DTO에 일관된 Swagger 문서화가 적용되었습니다.** 다른 인증 관련 DTO들과 일관된 스키마 어노테이션 구조를 유지하며, 팩토리 메서드의 포맷팅도 개선되어 전체적인 코드 품질이 향상되었습니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/strategy/KakaoAuthStrategy.kt (5)</summary> `3-9`: **적절한 import 추가입니다!** Jackson 어노테이션, 구조화된 로깅, 그리고 더 구체적인 예외 처리를 위한 import들이 잘 추가되었습니다. --- `27-27`: **올바른 로거 초기화** KotlinLogging을 사용한 로거 초기화가 적절합니다. --- `36-50`: **우수한 에러 처리 리팩토링** `runCatching`을 활용한 예외 처리와 메서드 추출로 코드 가독성과 유지보수성이 크게 향상되었습니다. 에러 로깅도 적절히 추가되었습니다. --- `87-95`: **깔끔한 사용자 생성 로직** 사용자 생성 로직이 별도 메서드로 잘 분리되었으며, 이메일이 없는 경우를 위한 폴백 처리도 적절합니다. --- `98-113`: **적절한 데이터 클래스 캡슐화** 데이터 클래스를 private으로 변경하고 @JsonProperty 어노테이션을 추가한 것이 좋습니다. Kakao API의 snake_case JSON 필드명을 Kotlin의 camelCase 관례에 맞게 매핑합니다. </details> <details> <summary>apis/src/main/kotlin/org/yapp/apis/auth/strategy/AppleAuthStrategy.kt (6)</summary> `3-3`: **ObjectMapper 의존성 주입 개선** JSON 파싱을 위해 ObjectMapper를 주입받도록 변경한 것이 좋습니다. 수동 문자열 파싱보다 안전하고 유지보수가 용이합니다. Also applies to: 19-21 --- `28-42`: **일관된 에러 처리 패턴** KakaoAuthStrategy와 동일한 에러 처리 패턴을 적용하여 일관성을 유지했습니다. 예외 처리와 로깅이 적절합니다. --- `75-83`: **적절한 Base64 디코딩 헬퍼 메서드** JWT 토큰에 사용되는 URL-safe Base64 디코딩을 위한 별도 메서드 추출이 좋습니다. 에러 처리도 적절합니다. --- `85-96`: **명확한 사용자 생성 로직** 이메일 필수 검증과 프로필 이미지가 null인 이유에 대한 주석이 적절합니다. Apple 인증의 특성을 잘 반영했습니다. --- `98-102`: **적절한 데이터 클래스 캡슐화** 데이터 클래스를 private으로 변경하여 구현 세부사항을 숨긴 것이 좋습니다. --- `44-73`: **타입 안전성 개선 제안** JWT 파싱 로직이 크게 개선되었습니다. 다만, raw Map 대신 Map<*, *>를 사용하면 타입 안전성을 더 높일 수 있습니다. ```diff -val payloadMap = objectMapper.readValue(payloadJson, Map::class.java) +val payloadMap = objectMapper.readValue(payloadJson, Map::class.java) as Map<*, *>Likely an incorrect or invalid review comment.
apis/src/main/kotlin/org/yapp/apis/auth/strategy/KakaoAuthStrategy.kt
Outdated
Show resolved
Hide resolved
* [BOOK-79] feat: RestClient 알라딘 API적용 (#18) * [BOOK-79] fix: IllegalArgumentException 500 공통에러로 떨어지는 문제 해결 (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 Controlller (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 DTO (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 외부 API Helper (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 UseCase (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 Service (#15) * [BOOK-79] feat: apis - 알라딘 도서검색, 도서상세검색 외부 API Response 정의 (#15) * [BOOK-79] feat: gateway - 도서관련 security permitAll (#15) * [BOOK-79] feat: domain - domain model (#15) * [BOOK-79] feat: infra - domain entity 설계 (#15) * [BOOK-79] refactor: global-util - HttpRequestMethodNotSupportedException 추가 (#15) * [BOOK-79] chore: infra external.yml파일 알라딘 api key 세팅 (#15) * [BOOK-79] refactor: infra user impl 분리 (#15) * [BOOK-79] refactor: infra - 알라딘 책 가격 부동소수점 오류를 위한 BigDecimal (#15) * [BOOK-79] refactor: infra - 알라딘 외부 API용 DTO분리 (#15) * [BOOK-79] refactor: apis - external yml group 추가 (#15) * [BOOK-79] refactor: apis - 요청 DTO값 분리 및 알라딘 외부용 API 분리 (#15) * [BOOK-79] refactor: �admin - external yml group 추가 (#15) * [BOOK-79] fix: apis - inner dto class 이름변경 (#15) * [BOOK-79] feat: infra - BookRepository 기능개발 (#15) * [BOOK-79] feat: �domain - BookRepository 기능개발 (#15) * [BOOK-79] refactor: infra,apis RestClient 각 외부 APi별 분리 (#15) * [BOOK-79] �chore: infra,apis 필요없는 코드 삭제 (#15) * [BOOK-79] refactor: apis,global-utils validation 강화 (#15)
🔗 관련 이슈
📘 작업 유형
📙 작업 내역
신규 기능
개선 및 변경
🧪 테스트 내역
🎨 스크린샷 또는 시연 영상 (선택)
✅ PR 체크리스트
💬 추가 설명 or 리뷰 포인트 (선택)
Summary by CodeRabbit
Summary by CodeRabbit
신규 기능
개선 및 변경
버그 수정
환경 및 설정
문서화