mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Refactor authentication and token handling.
This commit is contained in:
parent
1a8c7c42f4
commit
67732b9b5a
7 changed files with 50 additions and 70 deletions
12
lib/redis.js
12
lib/redis.js
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue