Skip to content

Conversation

@anandshukla15
Copy link

Description

session expiry implemention with jwt

Semver Changes

-code of session expiry of period 7 days and logout functionality

Checklist

I have read the Contributing Guidelines.

@04shubham7
Copy link
Member

@anandshukla15 pls resolve merge conflicts carefully at first

@anandshukla15
Copy link
Author

@04shubham7 done

@04shubham7 04shubham7 requested a review from Copilot October 26, 2025 06:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements JWT-based session management with a 7-day expiration period and logout functionality. The implementation introduces database-backed session tracking using MongoDB and automated cleanup of expired sessions.

Key changes:

  • Session persistence layer added via a new sessionModel to track active user sessions
  • Logout endpoint implemented to invalidate sessions by removing them from the database
  • Automated cron job scheduled to clean up expired sessions daily at 2 AM

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
backend/src/models/sessionModel.ts Defines the Session schema with TTL index for automatic MongoDB expiration
backend/src/controllers/authController.ts Creates session records during registration and login
backend/src/middleware/authMiddleware.ts Validates tokens against active sessions in the database
backend/src/routes/authRoutes.ts Adds logout endpoint to delete session records
backend/src/server.ts Schedules daily cron job to clean up expired sessions
backend/src/utils/generateToken.ts Refactored to use clearer variable naming (userId instead of id)
backend/package.json Adds node-cron dependency for scheduled tasks
backend/tsconfig.tsbuildinfo Updated build manifest to include sessionModel
Files not reviewed (1)
  • backend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

anandshukla15 and others added 3 commits October 26, 2025 16:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@04shubham7 04shubham7 left a comment

Choose a reason for hiding this comment

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

good work

@04shubham7
Copy link
Member

@anandshukla15 pls resolve merge conflicts

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.

2 participants