inactivity-logout
is a simple JavaScript package that automatically logs out users after a defined period of inactivity.
- Detects user inactivity based on mouse movement, keyboard activity, and touch events.
- Customizable timeout (e.g., 60 sec to 1 hour).
- Executes a callback function when the user is inactive.
- Supports session clearing and redirection.
npm install inactivity-logout
const InactivityLogout = require('inactivity-logout');
const logoutHandler = new InactivityLogout({
timeout: 120000, // 2 minutes
onLogout: () => {
console.log("User inactive. Logging out...");
// Perform logout actions like clearing session or redirecting
window.location.href = '/logout';
}
});
logoutHandler.start();
Option | Type | Default | Description |
---|---|---|---|
timeout |
Number |
300000 (5 min) |
Inactivity duration in milliseconds. |
onLogout |
Function | null |
Callback executed on inactivity. |
Run the test script:
node test.js
This project is licensed under the MIT License.