Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ 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')
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])
Expand Down Expand Up @@ -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]
}
Expand Down