refactor: ♻️ expose session max age as static getter
This commit is contained in:
parent
ca79b4a20d
commit
a1844176bb
|
@ -8,21 +8,24 @@ type SessionEntry<T extends unknown = unknown> = {
|
||||||
|
|
||||||
export class SessionStore {
|
export class SessionStore {
|
||||||
static #store = new Map<string, Session>()
|
static #store = new Map<string, Session>()
|
||||||
|
|
||||||
|
static get maxAge() {
|
||||||
|
const halfHour = 30 * 60 * 1_000
|
||||||
|
return Date.now() - halfHour
|
||||||
|
}
|
||||||
static createSession(): Session {
|
static createSession(): Session {
|
||||||
return new Session(this.#store)
|
return new Session(this.#store)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSession(uuid: string): Session | undefined {
|
static getSession(uuid: string): Session | undefined {
|
||||||
// Check session validity
|
// Check session validity
|
||||||
const halfHour = 30 * 60 * 1_000
|
|
||||||
const maxAge = Date.now() - halfHour
|
|
||||||
const session = this.#store.get(uuid)
|
const session = this.#store.get(uuid)
|
||||||
|
|
||||||
if (session === undefined) {
|
if (session === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.timestamp < maxAge) {
|
if (session.timestamp < this.maxAge) {
|
||||||
session.destroy()
|
session.destroy()
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue