Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

No description, website, or topics provided.

Resources

Packages

No packages published