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 {
|
||||
static #store = new Map<string, Session>()
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue