Skip to content

Add logout and token invalidation with Redis blacklist - #1040

Merged
nafiuishaaq merged 7 commits into
MentoNest:mainfrom
No-bodyq:feat/issue-976-logout-token-invalidation
Aug 2, 2026
Merged

Add logout and token invalidation with Redis blacklist#1040
nafiuishaaq merged 7 commits into
MentoNest:mainfrom
No-bodyq:feat/issue-976-logout-token-invalidation

Conversation

@No-bodyq

Copy link
Copy Markdown
Contributor

Closes #976

  • POST /auth/logout blacklists the current access token's jti in Redis with a TTL matching its remaining lifetime, and deletes the user's stored refresh tokens
  • POST /auth/logout-all does the same and additionally bumps user.tokenVersion, invalidating any other tokens that carry a tokenVersion claim
  • JwtAuthGuard now checks the Redis blacklist and, when present, the token's tokenVersion before authorizing a request, rejecting revoked tokens with 401 token_revoked
  • Added refresh_tokens and audit_logs tables (migration), with logout/logout-all events recorded to the audit log with timestamp and IP
  • New RedisModule/TokenBlacklistService (ioredis-backed), unit tests for the guard, service, controller, and blacklist service, plus an e2e scaffold

@drips-wave

drips-wave Bot commented Jul 25, 2026

Copy link
Copy Markdown

@No-bodyq Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@No-bodyq
No-bodyq force-pushed the feat/issue-976-logout-token-invalidation branch 2 times, most recently from 369613e to dc8577a Compare July 26, 2026 20:56
Rebuilds MentoNest#976 on top of the current wallet-auth architecture: wires
the app's existing RedisService (config/redis.module.ts) into a new
TokenBlacklistService, and connects it to JwtAuthGuard (fixing its
previously-unresolvable blacklistCheck constructor param) and to
AuthService.logout(), so a revoked access token's jti is rejected on
every subsequent request, across restarts and server instances.
@No-bodyq
No-bodyq force-pushed the feat/issue-976-logout-token-invalidation branch from dc8577a to dbc521d Compare July 26, 2026 21:00
No-bodyq added 6 commits July 26, 2026 22:38
- auth.controller.ts had two full AuthController class bodies concatenated
  (a botched prior merge), which broke parsing for the whole file and
  cascaded into unrelated eslint type-resolution errors repo-wide
- add missing @nestjs/swagger dependency (used throughout but never
  added to package.json)
- fix relative import paths in auth.service.ts (an extra '../' pointed
  outside src/auth, breaking NodeNext module resolution)
- add .js extensions to relative imports per the project's nodenext
  moduleResolution, removing further unresolved-type cascades
- remove JwtAuthGuard's unresolvable third constructor parameter (a bare
  function type Nest can never inject), small unused-import/no-await
  cleanups, and a wrong TypeORM option name (connectTimeout -> connectTimeoutMS)
- apply repo-wide prettier formatting (was never run on ~50 files)

Lint: 95 errors -> 0. Build: failing -> passing. Prettier: 51 files -> 0.
…ation

These specs were written against a device-aware, RefreshTokenService +
UsersService backed refresh-token design that was never wired into
AuthService/AuthController — the real implementation still uses the
simpler in-memory nonce/token-map flow plus this PR's Redis-backed
logout blacklist. Rewrite both specs to exercise what's actually
there, including coverage for the new blacklist-on-logout behavior.
@nafiuishaaq
nafiuishaaq merged commit c0b450e into MentoNest:main Aug 2, 2026
0 of 2 checks passed
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.

Logout and token invalidation

2 participants