inactivity-logout-piyush
v1.0.1
Published
inactivity-logout is a simple and lightweight JavaScript package that automatically logs out inactive users after a specified time. It listens for user actions like mouse movements, key presses, scrolling, and clicks. If no activity is detected within the
Downloads
5
Readme
Inactivity Logout
Description
inactivity-logout is a simple JavaScript package that automatically logs out users after a defined period of inactivity.
Features
- 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.
Installation
npm install inactivity-logout
Usage
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();Configuration Options
| Option | Type | Default | Description |
|-------------|---------|---------|-------------|
| timeout | Number | 300000 (5 min) | Inactivity duration in milliseconds. |
| onLogout | Function | null | Callback executed on inactivity. |
Testing
Run the test script:
node test.jsLicense
This project is licensed under the MIT License.
