fastify-secure-session icon indicating copy to clipboard operation
fastify-secure-session copied to clipboard

Multiple cookies

Open dominik-korsa opened this issue 3 years ago • 1 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Add support for different "instances" of the session plugin, with different cookie names and cookie options (different path/expiration date). This could be accomplished by allowing to specify the decorated field name (request.session by default) in plugin options.

Please keep in mind this will require changing the way types work, as the SessionData is currently set for the entire @fastify/secure-session module

Motivation

I need to keep a separate session for short-term (data expiring after closing tab) and long-term storage (user login token)

Example

const SecureSession = require('@fastify/secure-session');

fastify.register(SecureSession, {
  cookieName: 'long-term-cookie',
  cookie: {
    path: '/'
    expires: new Date('2137-01-01'),
  },
  field: 'longTermSession'
});
fastify.register(SecureSession, {
  cookieName: 'short-term-cookie',
  cookie: {
    path: '/'
    expires: undefined,
  },
  field: 'shortTermSession'
});

fastify.get('/', (request) => {
  console.log(request.longTermSession);
  console.log(request.shortTermSession);
});

dominik-korsa avatar Aug 22 '22 17:08 dominik-korsa

@dominik-korsa

Check out #163

Uzlopak avatar Aug 22 '22 18:08 Uzlopak

Closing as per previous comment

simoneb avatar Jan 15 '23 17:01 simoneb