Skip to content

refactor(auth): TokenService 추출 (P0-1 단계 4)#109

Merged
chanwoo7 merged 1 commit into
developfrom
refactor/auth-token-service
May 27, 2026
Merged

refactor(auth): TokenService 추출 (P0-1 단계 4)#109
chanwoo7 merged 1 commit into
developfrom
refactor/auth-token-service

Conversation

@chanwoo7
Copy link
Copy Markdown
Member

Summary

  • AuthService 의 토큰 발급·회전·해싱·쿠키 책임을 신규 TokenService 로 분리.
  • 중복되던 cookie option / request meta 헬퍼 (AuthCookieOptions / getUserAgent/getIp) 도 함께 추출하여
    AuthService 와 TokenService 가 공유.

Scope

  • 신규
    • `src/features/auth/helpers/auth-cookie-options.helper.ts` — cookie domain / secure / sameSite getters
    • `src/features/auth/helpers/auth-request-meta.helper.ts` — getUserAgent, getIp (pure)
    • TokenService (interface + impl + spec, TOKEN_SERVICE Symbol 토큰)
      • public: signAccessToken, getAccessExpiresSeconds, issueAuthTokens, rotateRefresh, sha256Hex, clearRefreshCookie
      • private: generateRefreshToken, getRefreshDays
  • 변경
    • AuthService: JwtService 직접 의존 제거, 토큰 관련 8 곳을 `this.tokens.*` 로 위임,
      extracted 5+ private helper 제거. AuthService 줄 수: 824 → 약 580.
    • AuthModule: TokenService 등록
    • 영향 spec 2 개 (auth.service / auth.seller.service) 에 TokenService 를 실 인스턴스로 주입.
      기존 refreshSessions/jwt mock 으로 회귀 없음.

P0-1 진행 상황

  • ✅ 단계 1: RefreshSessionRepository
  • ✅ 단계 2: AuditLogRepository
  • ✅ 단계 3: AccountRepository / SellerCredentialRepository
  • ✅ 단계 4: TokenService (본 PR)
  • ⏳ 단계 5: OidcLoginService 추출
  • ⏳ 단계 6: SellerCredentialService + logout 통합
  • ⏳ 단계 7: AuthService 잔여 정리 (facade 축소 또는 제거)

Impact

  • FE: 없음 (REST 엔드포인트·응답·에러 형태 동일)
  • DB: 변경 없음
  • Coverage: 1177 tests pass (TokenService spec 9 신규), 전 임계 통과

Test plan

  • yarn validate 로컬 통과
  • token.service.spec.ts 신규 단위테스트 (sign / hash / issue / rotate / clear)
  • auth.service / auth.seller.service spec 회귀 없음 (실 TokenService + 기존 repo mock)
  • CI 통과 확인

AuthService 의 토큰 발급·회전·해싱·쿠키 책임을 신규 TokenService 로 분리.
플랜의 단계 4 (issueAuthTokens, sha256Hex, signAccessToken 등) 를 수행하면서
중복되던 cookie option / request meta 헬퍼도 함께 추출.

- 신규 헬퍼
  - AuthCookieOptions (cookie domain/secure/sameSite getters) — TokenService 와
    AuthService 가 공유
  - auth-request-meta helper (getUserAgent, getIp) — 동일 사유로 공유
- 신규 TokenService (interface + impl + spec, DI Token 패턴)
  - public: signAccessToken, getAccessExpiresSeconds, issueAuthTokens,
    rotateRefresh, sha256Hex, clearRefreshCookie
  - private: generateRefreshToken, getRefreshDays
- AuthService 변경
  - JwtService 직접 의존 제거 (TokenService 위임)
  - 토큰 관련 8 곳을 this.tokens.* 로 위임
  - extracted 5 개 private helper 제거 (signAccessToken, issueAuthTokens,
    rotateRefresh, sha256Hex, getAccessExpires/RefreshDays/CookieDomain/...)
- AuthModule: TokenService 를 TOKEN_SERVICE 토큰으로 등록
- AuthService spec / AuthService (seller) spec: TokenService 를 실제 인스턴스로
  주입 (기존 refreshSessions / jwt mock 그대로 사용, 회귀 없음)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c417f1a4-a2b6-4aa3-b13b-ebba7965a0b7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/auth-token-service

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 93.50649% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...eatures/auth/helpers/auth-cookie-options.helper.ts 76.92% 1 Missing and 2 partials ⚠️
.../features/auth/helpers/auth-request-meta.helper.ts 60.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 97.13% 3353/3452
🟢 Branches 92.99% 1128/1213
🟢 Functions 93.53% 636/680
🟢 Lines 97.43% 3074/3155

Test suite run success

1177 tests passing in 134 suites.

Report generated by 🧪jest coverage report action from 98905fa

@chanwoo7 chanwoo7 merged commit 173f134 into develop May 27, 2026
10 checks passed
@chanwoo7 chanwoo7 deleted the refactor/auth-token-service branch May 27, 2026 17:53
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.

1 participant