# express-single-session

> Express middleware that enforces a single session per user

Latest version **1.0.0** (published 2014-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-single-session
pnpm add express-single-session
yarn add express-single-session
bun add express-single-session
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-04-15 |
| First published | 2014-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Alan Shaw |
| Maintainers | alanshaw |
| Keywords | express, session, single, concurrent |

## Links

- npm: https://www.npmjs.com/package/express-single-session
- Repository: https://github.com/alanshaw/express-single-session
- Issues: https://github.com/alanshaw/express-single-session/issues
- npm.io page: https://npm.io/package/express-single-session

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-04-15

## README

express-single-session
===
Express middleware that enforces a single session per user.

Example
---

```js
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:

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

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

```js
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.

---
_Source: https://npm.io/package/express-single-session · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
