From 0372e067a592f541df1ceda843394108f3d9b1ab Mon Sep 17 00:00:00 2001 From: Daan Roet Date: Wed, 16 Dec 2020 15:32:25 +0100 Subject: [PATCH] fix: don't use decorateRequest with reference types see FastifyDeprecation [FSTDEP006] --- lib/fastifySession.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/fastifySession.js b/lib/fastifySession.js index 37aea62..578c650 100644 --- a/lib/fastifySession.js +++ b/lib/fastifySession.js @@ -18,11 +18,16 @@ function session (fastify, options, next) { fastify.decorate('decryptSession', (sessionId, request, callback) => { decryptSession(sessionId, options, request, callback) }) - fastify.decorateRequest('sessionStore', options.store) - fastify.decorateRequest('session', {}) + fastify.decorateRequest('sessionStore', null) + fastify.decorateRequest('session', null) fastify.decorateRequest('destroySession', destroySession) fastify.addHook('preValidation', preValidation(options)) fastify.addHook('onSend', onSend(options)) + fastify.addHook('onRequest', (req, reply, next) => { + req.sessionStore = options.store + req.session = {} + next() + }) next() }