npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@travishorn/session-timeout

v2.0.5

Published

Warn users when their session is about to expire. Dependency-free.

Downloads

1,934

Readme

Session Timeout

Warn users when their session is about to expire. Dependency-free.

When this function is called (usually each time a page is loaded), a timer starts in the background. When the timer goes off, a warning is displayed to the user that their session is about to expire. The user has two options: Log out now or stay connected. If they choose to log out, they are brought to your site's log out page. If they choose to stay connected, a keep-alive URL is requested in the background, the warning is hidden, and the timer resets.

This project is the successor to jquery-sessionTimeout. I built this new version to remove the dependency on jQuery and jQuery UI.

Animated demonstration

Installation

Method 1: CDN

Include the script on your page via UNPKG.

<script src="https://unpkg.com/@travishorn/session-timeout"></script>

Method 2: Download

Download dist/session-timeout.js.

Include it on your page.

<script src="session-timeout.js"></script>

Method 3: ES6 Module using npm and webpack (or similar)

Install via npm.

> npm install @travishorn/session-timeout

Include it in your scripts.

import sessionTimeout from '@travishorn/session-timeout';

Usage

Call it in JavaScript.

sessionTimeout();

Provide options as an object.

sessionTimeout({
  warnAfter: 60000,
  message: 'Are you still there?',
});

Options

appendTimestamp

If true, appends the a timestamp parameter to the end of the keep-alive URL with each request. This can prevent caching issues by guaranteeing the URL is unique.

Default: false

Example URL: /keep-alive?time=1551203965297

keepAliveMethod

The HTTP method to use when making the keep-alive request.

Default: POST

keepAliveUrl

When the user clicks the "Stay connected" button, this URL is requested in the background to keep their session alive.

Default: /keep-alive

logOutBtnText

The text on the log out button.

Default: Log out now

logOutUrl

When the user clicks the "Log out now" button, their browser is directed to this URL.

Default: /log-out

titleText

The text displayed at the top of the dialog.

Default: Session Timeout

message

The message to display when warning the user of inactivity.

Default: Your session is about to expire.

stayConnectedBtnText

The text on the "stay connected" button.

Default: Stay connected

timeOutAfter

The amount of time, in milliseconds, to wait until automatically timing out the user and redirecting their client to the time-out URL. You will usually want to set this to the same amount of time your server keeps sessions alive. This timer gets reset if the users clicks the "stay connected" button on the warning dialog.

Default: 1200000 (20 minutes)

timeOutUrl

Once the time out period has elapsed, the user's browser will be directed to this URL.

Default: /timed-out

warnAfter

The amount of time, in milliseconds, to wait until displaying a warning to the user. If the user clicks the "stay connected" button, the warning disappears, and the timer is reset. The warning will re-appear after the same amount of time after reset.

Default: 900000 (15 minutes)