Added rev_id column. Updated redis calls.

This commit is contained in:
Mike Cao 2022-11-07 16:22:49 -08:00
parent a9112f39ec
commit 3485b6268b
18 changed files with 133 additions and 79 deletions

View file

@ -1,4 +1,4 @@
import { parseSecureToken, parseToken } from 'next-basics';
import { getRandomChars, parseSecureToken, parseToken } from 'next-basics';
import { getUser, getWebsite } from 'queries';
import debug from 'debug';
import { SHARE_TOKEN_HEADER, TYPE_USER, TYPE_WEBSITE } from 'lib/constants';
@ -6,10 +6,19 @@ import { secret } from 'lib/crypto';
const log = debug('umami:auth');
export function generateAuthToken() {
return getRandomChars(32);
}
export function getAuthToken(req) {
const token = req.headers.authorization;
return token.split(' ')[1];
}
export function parseAuthToken(req) {
try {
const token = req.headers.authorization;
return parseSecureToken(token.split(' ')[1], secret());
return parseSecureToken(getAuthToken(req), secret());
} catch (e) {
log(e);
return null;

0
lib/cache.js Normal file
View file

View file

@ -41,6 +41,12 @@ async function set(key, value) {
return redis.set(key, value);
}
async function del(key) {
await connect();
return redis.del(key);
}
async function connect() {
if (!redis) {
redis = process.env.REDIS_URL && (global[REDIS] || getClient());
@ -49,4 +55,4 @@ async function connect() {
return redis;
}
export default { enabled, client: redis, log, connect, get, set };
export default { enabled, client: redis, log, connect, get, set, del };