mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Added redis check to verify.
This commit is contained in:
parent
13fd3ccd16
commit
208fcb8418
4 changed files with 20 additions and 13 deletions
|
|
@ -7,7 +7,7 @@ import { secret } from 'lib/crypto';
|
|||
const log = debug('umami:auth');
|
||||
|
||||
export function generateAuthToken() {
|
||||
return getRandomChars(32);
|
||||
return `auth:${getRandomChars(32)}`;
|
||||
}
|
||||
|
||||
export function getAuthToken(req) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import debug from 'debug';
|
|||
import cors from 'cors';
|
||||
import { findSession } from 'lib/session';
|
||||
import { parseAuthToken, parseShareToken } from 'lib/auth';
|
||||
import redis from 'lib/redis';
|
||||
|
||||
const log = debug('umami:middleware');
|
||||
|
||||
|
|
@ -25,14 +24,11 @@ export const useAuth = createMiddleware(async (req, res, next) => {
|
|||
const token = await parseAuthToken(req);
|
||||
const shareToken = await parseShareToken(req);
|
||||
|
||||
const key = `auth:${token?.authKey}`;
|
||||
const data = redis.enabled ? await redis.get(key) : token;
|
||||
|
||||
if (!data && !shareToken) {
|
||||
if (!token && !shareToken) {
|
||||
log('useAuth:user-not-authorized');
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
req.auth = { ...data, shareToken };
|
||||
req.auth = { ...token, shareToken };
|
||||
next();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue