Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
@solid-primitives/idle
Advanced tools
A primitive to observe the user's idle status and react to its changes.
createIdleTimer
- A primitive to track the user's idle status and take appropriate action.
npm install @solid-primitives/idle
# or
yarn add @solid-primitives/idle
# or
pnpm add @solid-primitives/idle
createIdleTimer
provides different accessors and methods to observe the user's idle status and react to its changing.
const App: Component = () => {
const { isIdle, isPrompted, reset } = createIdleTimer({
onIdle: logout,
idleTimeout: 300_000,
promptTimeout: 60_000
});
return (
<Switch fallback={<ClientPage />}>
<Match when={isIdle()}>
<LoggedOut />
</Match>
<Match when={isPrompted()}>
<PromptPopup onConfirm={reset /*or stop*/} />
</Match>
</Switch>
);
};
To interact with the timers, createIdleTimer
provides:
Accessor<boolean>
; these two accessors report the user status. They do not concur.() => void
; allow rispectively to start and stop the timers, and to reset them. start
and reset
, create a custom manualstart
and manualreset
event, that will be passed to the onIdle
and onPrompt
callbacks if no oher activity occurs (there's another custom event, mount
, created when timers start automatically). Finally stop
and reset
don't trigger onActive
.createIdleTimer
takes as an optional argument an object with the timer's configuration options. Each key has a default value.
The options are:
number
; time of user's inactivity in milliseconds before the idle status changes to idle. This time is extended by the promptTimeout
option. It defaults to 15 minutes.number
; to meet the typical usecase when we want to prompt the user to check if we they are still active, an additional timer starts running right after the idleTimeout expires. In this time slot, the user is in the prompt phase, whose duration is decided by promptTimout
. It defaults to 0.(evt: Event) => void
; callback triggered when the user status passes to idle. When invoked, the last event fired before the prompt phase will be passed as parameter. Events fired in the prompt phase will not count. It defaults to an empty function.(evt: Event) => void
; when the idleTimeout
expires, before declaring the idle status, onPrompt
callback is fired, starting the prompt timer. When invoked, the last event fired before the prompt phase will be passed as a parameter. It defaults to an empty function.(evt: Event) => void
; callback called when the user resumes activity after having been idle (resuming from prompt phase doesn't trigger onActive
). The event that triggered the return to activity is passed as a parameter. It defaults to an empty function.boolean
; requires the event-listeners to be bound manually by using the start
method, instead of on mount. It defaults to false.EventTypeName[]
; a list of the DOM events that will be listened to in order to monitor the user's activity. The events must be of EventTypeName
type (it can be imported). The list defaults to ['mousemove', 'keydown', 'wheel', 'resize', 'mousewheel', 'mousedown', 'pointerdown', 'touchstart', 'touchmove', 'visibilitychange']
HTMLElement
; DOM element to which the event listeners will be attached. It defaults to document
.Here is a working example: https://stackblitz.com/edit/vitejs-vite-dwxlhp?file=src/App.tsx
This primitive is inspired by react-idle-timer
See CHANGELOG.md
FAQs
A primitive to observe the user's idle status and react to its changes.
We found that @solid-primitives/idle demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.