UNPKG

authkit-js

Version:

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

35 lines (22 loc) 719 B
// Redis-backed refresh token store class RedisRefreshStore { constructor(redisClient, keyPrefix = 'authkit:rt:') { this.client = redisClient; this.prefix = keyPrefix; } key(userId) { return `${this.prefix}${userId}`; } async get(userId) { return await this.client.get(this.key(userId)); } async set(userId, token, ttlSec) { const k = this.key(userId); // Use positional args form which is supported by ioredis and node-redis const seconds = ttlSec || 0; if (seconds > 0) { await this.client.set(k, token, 'EX', seconds); } else { await this.client.set(k, token); } } async del(userId) { await this.client.del(this.key(userId)); } } module.exports = { RedisRefreshStore };