Refactor authentication and token handling.

This commit is contained in:
Mike Cao 2022-11-08 22:58:52 -08:00
parent 1a8c7c42f4
commit 67732b9b5a
7 changed files with 50 additions and 70 deletions

View file

@ -9,7 +9,7 @@ let redis;
const enabled = Boolean(process.env.REDIS_URL);
function getClient() {
if (!process.env.REDIS_URL) {
if (!enabled) {
return null;
}
@ -32,7 +32,11 @@ function getClient() {
async function get(key) {
await connect();
return JSON.parse(await redis.get(key));
try {
return JSON.parse(await redis.get(key));
} catch {
return null;
}
}
async function set(key, value) {
@ -48,8 +52,8 @@ async function del(key) {
}
async function connect() {
if (!redis) {
redis = process.env.REDIS_URL && (global[REDIS] || getClient());
if (!redis && enabled) {
redis = global[REDIS] || getClient();
}
return redis;