Skip to content

feat: implement Logout API across all layers / ユーザーログアウトAPIの全層実装#539

Merged
zigzagdev merged 9 commits into
feat/userfrom
feat/user-logout
Jul 15, 2026
Merged

feat: implement Logout API across all layers / ユーザーログアウトAPIの全層実装#539
zigzagdev merged 9 commits into
feat/userfrom
feat/user-logout

Conversation

@zigzagdev

Copy link
Copy Markdown
Owner

Motivation / 目的

Implement POST /api/v1/user/logout API to invalidate the current session token using Laravel Sanctum.
Each layer was developed on its own branch and merged in sequence.

現在のセッショントークンのみを無効化するログアウト機能(POST /api/v1/user/logout)を実装しました。
DDD の各層を個別ブランチで実装して順次マージしています。


What I have done / 実施内容

Infrastructure Layer

  • TokenServiceInterface: revokeCurrentToken(string $plainTextToken): void を追加
  • SanctumTokenService: PersonalAccessToken::findToken() でトークンを検索し削除。存在しない場合は何もしない(冪等)
  • UserRepositroyInterface の変更なし(ログアウトはトークン削除のみで、ユーザーデータの取得は不要なため)

Application Layer

  • LogoutUseCase: handle(string $plainTextToken): void
    • TokenServiceInterface::revokeCurrentToken($plainTextToken) を呼び出す
    • Login と同様に Command/Input オブジェクトは作成しない

Presentation Layer

  • AuthController: logout アクションを追加
    • $request->bearerToken() で現在のトークンを取得し LogoutUseCase::handle() に渡す
    • 200 / 401 / 500 のレスポンスを返す
  • routes/api.php: POST /v1/user/logoutauth:sanctum ミドルウェア付きで登録

Test Results / テスト結果

Integration Tests

  • SanctumTokenServiceTest::test_revokeCurrentToken_deletes_the_given_token
  • SanctumTokenServiceTest::test_revokeCurrentToken_does_nothing_when_token_not_found
  • LogoutTest::test_logout_returns_200_when_authenticated
  • LogoutTest::test_logout_returns_401_when_unauthenticated
  • LogoutTest::test_logout_returns_500_on_unexpected_error

Unit Tests

  • LogoutUseCaseTest::test_handle_revokes_current_token
  • LogoutUseCaseTest::test_handle_propagates_exception_when_revocation_fails

Closes #408

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.21%. Comparing base (7ce1092) to head (bf1b3f3).
⚠️ Report is 10 commits behind head on feat/user.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##             feat/user     #539      +/-   ##
===============================================
+ Coverage        61.75%   62.21%   +0.45%     
- Complexity        1585     1604      +19     
===============================================
  Files              132      135       +3     
  Lines             8153     8252      +99     
===============================================
+ Hits              5035     5134      +99     
  Misses            3118     3118              
Files with missing lines Coverage Δ
...kages/Domains/User/Service/SanctumTokenService.php 100.00% <100.00%> (ø)
...ins/User/Tests/Service/SanctumTokenServiceTest.php 100.00% <100.00%> (ø)
...res/CommandUseCases/UseCase/User/LogoutUseCase.php 100.00% <100.00%> (ø)
...pp/Packages/Features/Controller/AuthController.php 100.00% <100.00%> (ø)
...atures/Tests/CommandUseCases/LogoutUseCaseTest.php 100.00% <100.00%> (ø)
src/app/Packages/Features/Tests/LogoutTest.php 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…layer

feat: implement Presentation layer for User Logout / ユーザーログアウトのPresentation層実装
@zigzagdev zigzagdev self-assigned this Jul 15, 2026
@zigzagdev zigzagdev linked an issue Jul 15, 2026 that may be closed by this pull request

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Ok

@zigzagdev
zigzagdev merged commit 0ea56e1 into feat/user Jul 15, 2026
25 checks passed
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.

User Logout

1 participant