UNPKG

authkit-js

Version:

Express auth toolkit (JWT, Sessions with Redis, Google/GitHub OAuth) in JavaScript

23 lines (15 loc) 494 B
class MemorySessionStore { constructor() { this.map = new Map(); } async get(sessionId) { const e = this.map.get(sessionId); if (!e) return null; if (Date.now() > e.expiresAt) { this.map.delete(sessionId); return null; } return e.data; } async set(sessionId, data, ttlSec) { const expiresAt = Date.now() + ttlSec * 1000; this.map.set(sessionId, { data, expiresAt }); } async del(sessionId) { this.map.delete(sessionId); } } module.exports = { MemorySessionStore };