Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Auto-Logout Users After a Period of Inactivity #1318

Open
officiabreezy opened this issue Mar 1, 2025 · 1 comment
Open

[FEAT] Auto-Logout Users After a Period of Inactivity #1318

officiabreezy opened this issue Mar 1, 2025 · 1 comment
Labels

Comments

@officiabreezy
Copy link

Description

Implement Auto-Logout After Inactivity in NestJS's to automatically logged users out after a period of inactivity. This prevents unauthorized access in case a session remains open on a shared or public device. This feature should track user activity and invalidate the session/token after a set time of inactivity.

Acceptance Criteria

  • Track user activity and reset the inactivity timer upon interaction.
  • Automatically log out users after inactivity (e.g., 15 minutes).
  • Invalidate tokens/sessions after timeout.
  • Ensure users receive a 401 response when trying to use an expired session.

Purpose

  • Prevent unauthorized access after long inactivity.
  • Notify users before auto-logout, allowing them to extend the session.
  • Expire unused tokens to prevent token abuse.
  • Many secure systems implement auto-logout to protect users.

Requirements

  • Track user activity (e.g. Monitor user requests, Reset the inactivity timer etc.)
  • Destroy session (if using session-based authentication).
  • Send a warning response (You will be logged out in 1 minute due to inactivity).
  • Allow users to refresh the session if still active.
  • Return a 401 Unauthorized response when a user tries to access an expired session.

Expected Outcome

JSON Response on Auto-Logout

  • When session expires due to inactivity:
{
 "status":  "error",
  "status code": 401,
  "message":  "Session expired due to inactivity. Please log in again.",
  "data": {}
}
  • When warning user before auto-logout:
{
 "status": "warning",
  "status code": 200,
  "message":  "You will be logged out in 1 minute due to inactivity. Click 
   here to stay signed in.",
  "data": {}
}
@TheCodeGhinux
Copy link
Contributor

Is this needed??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants