No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Latest commit a4b8e44 Mar 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Add integration test with abstract-cache-mongo Mar 9, 2018
.editorconfig 🤘 Nov 13, 2017
.gitignore 🤘 Nov 13, 2017
.travis.yml Fix travis config Mar 9, 2018
Readme.md Fix #1 Nov 22, 2017
docker-compose.yml Add integration test with abstract-cache-mongo Mar 9, 2018
package.json Add integration test with abstract-cache-mongo Mar 9, 2018
plugin.js Update Fastify and dependencies Mar 7, 2018

Readme.md

fastify-server-session

This is a plugin for Fastify that facilitates keep state for clients between requests via server-side storage.

Requirements:

Example

const fastify = require('fastify')()
fastify
  .register(require('fastify-cookie'))
  .register(require('fastify-caching'))
  .register(require('fastify-server-session'), {
    secretKey: 'some-secret-password-at-least-32-characters-long',
    sessionMaxAge: 900000, // 15 minutes in milliseconds
    cookie: {
      domain: '.example.com',
      path: '/'
    }
  })

fastify.get('/one', (req, reply) => {
  req.session.foo = 'foo'
  reply.send()
})

fastify.get('/two', (req, reply) => {
  reply.send({foo: req.session.foo})
})

Options

The plugin accepts an options object with the following properties:

  • secretKey (Default: undefined): this is a required property that must be a string with a minimum of 32 characters.
  • sessionCookieName (Default: sessionid): a string to name the cookie sent to the client to track the session.
  • sessionMaxAge (Default: 1800000): a duration in milliseconds for which the sessions will be valid.
  • cookie: an options as described in the cookie module's documentation. The default value is:
    • domain: undefined
    • expires: same as sessionMaxAge
    • httpOnly: true
    • path: undefined
    • sameSite: true

License

MIT License