feat: add WsJwtAuthGuard to CollaborationGateway and periodic session index cleanup#920
Merged
RUKAYAT-CODER merged 1 commit intoJun 28, 2026
Conversation
|
@Nimatstar 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! 🚀 |
… index cleanup - Create WsJwtAuthGuard that validates JWT from handshake auth.token or query.token - Apply @UseGuards(WsJwtAuthGuard) to CollaborationGateway class - Register JwtModule in CollaborationModule to provide JwtService - Add addSessionToUserIndex/removeSessionFromUserIndex/getUserSessionIds to SessionService - Add SessionCleanupTask with @Cron(EVERY_HOUR) that removes stale members from user:sessions:{userId} sorted sets and tracks removals via a Prometheus counter Closes rinafcode#885 Closes rinafcode#887
5ec5621 to
7fb1625
Compare
Contributor
|
Thank you for contributing to the project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add WebSocket authentication guard to CollaborationGateway using JWT validation #887 — Created
WsJwtAuthGuardthat validates JWT tokens from WebSocket handshake (auth.tokenor query param?token=). Applied@UseGuards(WsJwtAuthGuard)toCollaborationGatewayso unauthenticated clients are rejected before any message handler runs.JwtModuleis now registered inCollaborationModule.Add periodic expired session cleanup job to prevent Redis memory growth #885 — Added three Redis sorted-set helpers to
SessionService(addSessionToUserIndex,removeSessionFromUserIndex,getUserSessionIds) to maintainuser:sessions:{userId}indexes. CreatedSessionCleanupTaskwith an hourly@Cronjob that scans all index keys, checks whether each session still exists in Redis, removes stale entries, and increments asession_cleanup_removed_totalPrometheus counter.Test plan
pnpm run lint:ci— no lint errorspnpm run build— TypeScript compiles cleanlysrc/collaboration/guards/ws-jwt-auth.guard.spec.ts— 5 tests: missing token, invalid token, valid auth.token, valid query.token, token precedencesrc/session/tasks/session-cleanup.task.spec.ts— 5 tests: empty scan, stale removal, live session kept, multi-page cursor, error resiliencesrc/session/session.service.spec.ts— existing 13 tests still passcloses #885
closes #887