idle-session-timeout
Idle session timeout is a security and resource management feature that automatically logs a user out after a period of inactivity.
Installation
npm i idle-session-timeout
Example
import { IdleSessionTimeout } from "idle-session-timeout";
let session = new IdleSessionTimeout(5 * 60 * 1000);
session.onTimeOut = () => {
console.log("timeOut");
};
session.onTimeLeftChange = (timeLeft) => {
console.log(`${timeLeft} ms left`);
};
session.start();
session.reset();
session.dispose();
let timeLeft = session.getTimeLeft();
By default the counter is automatically reset on those events:
- page load
- mouse move
- mouse down
- mouse up
- key press
- DOM Mouse Scroll
- mouse wheel
- MS Pointer Move
- click
- scroll
- touch start
- touch move
- touch end
if for some reason you want to chose the events for the reset you can use
import { IdleSessionTimeout } from "idle-session-timeout";
let session = new IdleSessionTimeout(5 * 60 * 1000, "click", "mousemove", ... etc );