From a1844176bbd3c92a77d8322a396942d3c963f410 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Thu, 13 Jun 2024 12:16:23 +0200 Subject: [PATCH] refactor: :recycle: expose session max age as static getter --- src/session/mod.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/session/mod.ts b/src/session/mod.ts index 28748b4..dfd1f43 100644 --- a/src/session/mod.ts +++ b/src/session/mod.ts @@ -8,21 +8,24 @@ type SessionEntry = { export class SessionStore { static #store = new Map() + + static get maxAge() { + const halfHour = 30 * 60 * 1_000 + return Date.now() - halfHour + } static createSession(): Session { return new Session(this.#store) } static getSession(uuid: string): Session | undefined { // Check session validity - const halfHour = 30 * 60 * 1_000 - const maxAge = Date.now() - halfHour const session = this.#store.get(uuid) if (session === undefined) { return undefined } - if (session.timestamp < maxAge) { + if (session.timestamp < this.maxAge) { session.destroy() return undefined }