@sr-net/session-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

session-middleware

npm TravisCI Coveralls David

Usage

The middleware needs a sr-net/auth service to use. Clone and run it locally before using this middleware.

import { Session } from '@sr-net/session-middleware'

app.use(
  Session({
    url: 'http://localhost:3100', // Url to running auth service
    domain: 'stratroulette.net', // Domain server is running on
  })
)

app.use(ctx => {
  ctx.session.id // Session ID
  ctx.session.maxAge // Session lifetime
  ctx.session.user // Session's User, if logged in
  ctx.session.isLoggedIn // Alias for !!ctx.session.user
  ctx.session.identifier // User UUID if logged in, otherwise Session ID

  ctx.session.foo = 'baz' // Set any variable and it will be saved to the Auth service
})

Testing

yarn test

Readme

Keywords

none

Package Sidebar

Install

npm i @sr-net/session-middleware

Weekly Downloads

0

Version

1.5.0

License

AGPL-3.0

Unpacked Size

49.9 kB

Total Files

12

Last publish

Collaborators

  • sr-net