New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

express-single-session

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-single-session

Express middleware that enforces a single session per user

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
38
280%
Maintainers
1
Weekly downloads
 
Created
Source

express-single-session

Express middleware that enforces a single session per user.

Example

var express = require("express")
  , enforceSingleSession = require("express-single-session")("_id")

var app = express()

app.use(express.session())

function loginMiddleware (req, res, next) {
  // Login your user here - this could be passportjs or whatever
  // Set req.user to be the logged in user
  next()
}

app.post("/login", loginMiddleware, enforceSingleSession, function (req, res) {
  return res.json({message: "Authentication success"})
})

Usage

Create a new single session middleware function:

var enforceSingleSession = require("express-single-session")()

Pass the id field on your user object if different to "_id":

var enforceSingleSession = require("express-single-session")("id")

Ensure the middleware that logs in your user adds your logged in user object to req.user.

The module stores a map of user ID's to session ID's. When a user is logged in, the module removes the express session (from req.sessionStore.sessions) with the session ID it has stored and associates the current req.sessionID with that user.

Keywords

express

FAQs

Package last updated on 15 Apr 2014

Did you know?

Socket

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.

Install

Related posts