authkit-js
Version:
Express auth toolkit (JWT, Sessions with Redis, Google/GitHub OAuth) in JavaScript
22 lines (14 loc) • 572 B
JavaScript
// Pass an ioredis or node-redis compatible client with get/set/del
class RedisSessionStore {
constructor(redisClient) { this.client = redisClient; }
async get(sessionId) {
const data = await this.client.get(sessionId);
return data ? JSON.parse(data) : null;
}
async set(sessionId, data, ttlSec) {
// Use positional args form which is supported by ioredis and node-redis
await this.client.set(sessionId, JSON.stringify(data), 'EX', ttlSec);
}
async del(sessionId) { await this.client.del(sessionId); }
}
module.exports = { RedisSessionStore };