From aa1e1d1844877ddaf0b4fb2aaf6eb0f7ad3ed025 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Mon, 15 Aug 2022 17:08:29 +0200 Subject: [PATCH] remove addDataToSession --- lib/session.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/session.js b/lib/session.js index 60953e6..dd33b6b 100644 --- a/lib/session.js +++ b/lib/session.js @@ -11,7 +11,6 @@ const stringify = configureStringifier({ bigint: false }) const maxAge = Symbol('maxAge') const secretKey = Symbol('secretKey') const sign = Symbol('sign') -const addDataToSession = Symbol('addDataToSession') const generateId = Symbol('generateId') const requestKey = Symbol('request') const cookieOptsKey = Symbol('cookieOpts') @@ -19,14 +18,21 @@ const originalHash = Symbol('originalHash') const hash = Symbol('hash') module.exports = class Session { - constructor (request, idGenerator, cookieOpts, secret, prevSession = {}) { + constructor (request, idGenerator, cookieOpts, secret, prevSession) { this[generateId] = idGenerator - this.cookie = new Cookie(cookieOpts) this[cookieOptsKey] = cookieOpts this[maxAge] = cookieOpts.maxAge this[secretKey] = secret - this[addDataToSession](prevSession) this[requestKey] = request + this.cookie = new Cookie(cookieOpts) + + if (prevSession) { + // Copy over values from the previous session + for (const key in prevSession) { + (key !== 'cookie') && (this[key] = prevSession[key]) + } + } + this.touch() if (!this.sessionId) { this.sessionId = this[generateId](this[requestKey]) @@ -67,14 +73,6 @@ module.exports = class Session { } } - [addDataToSession] (prevSession) { - for (const key in prevSession) { - if (key !== 'cookie') { - this[key] = prevSession[key] - } - } - } - get (key) { return this[key] }