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

react-session-control

v2.0.12

Published

Component to provide session control. It controls how long the user can be inactive and observes the storage checking for token existence.

Downloads

25

Readme

React Session Control

React Session Control is a lib to provide session control to your application. It can help you to manage the inactivity time and token existence.

Features

Inactivity time

Using the component AuthenticatedSessionControl you can set the maximum time for the user stay inactive and use a callback to do some action after this time. The inactivity time is calculated using all tabs.

Sync tabs

Using the component AuthenticatedSessionControl and UnauthenticatedSessionControl you can syncronize authentication status between tabs. When one tab disconects or conects the other one follows the action.

If the inactivity modal is open on one or more tabs and if one of them is activated, only it will continue with the modal.

Getting started

Prerequisites

Just install and use!

Installing

npm install --save react-session-control

Using

Basicaly the lib provide two componentes:

UnauthenticatedSessionControl

Component to put in your unauthenticated area in your app to warn you when token is set by other tabs.

import { UnauthenticatedSessionControl } from  'react-session-control';

//Should render after authentication.
export function Login(){
	function handleSessionControlLogin(logoutType){
		//Do your logic here...
	
	}
	return ( 
		<>
		<UnauthenticatedSessionControl
			storageTokenKey="token"
			onLogin={handleSessionControlLogin}
		/>
		//your code... 
		</>	
	)
}
Props

storageToken

Key do check existence in local storage. If you dont pass this config the component will not check storage. Required

tokenChangeDebounceTime

The time in miliseconds to debounce token changes. default: 500

AuthenticatedSessionControl

Component to put in a authenticated area in your app to warn you when the inacitivity time is over, the user click in logout inside modal or if the token has been removed by other tabs.

import { AuthenticatedSessionControl, LogoutTypes } from  'react-session-control';

//Should render after authentication.
export function Layout(){

	function handleSessionControlLogout(logoutType){
		//Do yout logout logic here...
	}

	return ( 
		<>
		<AuthenticatedSessionControl
			inactivityTimeout={900}
			modalInactivityTimeout={30}
			storageTokenKey="token"
			onLogout={handleSessionControlLogout}
		/>
		//your code... 
		</>	
	)
}
Props

inactivityTimeout

Inictivity timeout in seconds. Required

modalInactivityTimeout

Inictivity timeout when modal is open in seconds. Required

onLogout

Callback to be called when user ends his inactivity time limit, click in logout button or lose his token. Required

storageToken

Key do check existence in local storage. If you dont pass this config the component will not check storage. default: undefined

title

Title to display in modal header. default: 'Inactivity alert'

message

Message to display in modal header. default: 'You have been inactive for a long time. Do you want to remain logged in?'

timerMessage

Message to display before time count in modal. default: 'You will be disconnected in: '

continueButtonText

Text to display in continue button. default: 'Continue'

logoutButtonText

Text to display in logout button. default: 'Logout'

showDocumentTitleAlert

If should display document title alert. default: true

documentTitleAlertText

The text displayed as document title case showDocumentTitleAlert is true. default: 'INACTIVITY ALERT'

tokenChangeDebounceTime

The time in miliseconds to debounce token changes. default: 500

userActivityThrottleTime

The time in miliseconds to throttle user activity. default: 500

debug

If the component is in debug mode. default: false

onInactivityTimeout

Callback to be called when inactivy ends.

onInactivityModalTimeout

Callback to be called when modal inactivy ends.

renderModal

Modal element to render.

Authors

  • Felipe Laera - Software Engineer

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details