mirror of
https://github.com/kremalicious/umami.git
synced 2025-01-27 02:26:18 +01:00
Updated token payload.
This commit is contained in:
parent
cd9036adaf
commit
1c64800157
@ -7,9 +7,11 @@ import { secret } from 'lib/crypto';
|
|||||||
const log = debug('umami:auth');
|
const log = debug('umami:auth');
|
||||||
|
|
||||||
export function getAuthToken(req) {
|
export function getAuthToken(req) {
|
||||||
const token = req.headers.authorization;
|
try {
|
||||||
|
return req.headers.authorization.split(' ')[1];
|
||||||
return token.split(' ')[1];
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseAuthToken(req) {
|
export function parseAuthToken(req) {
|
||||||
|
@ -26,24 +26,25 @@ export const useSession = createMiddleware(async (req, res, next) => {
|
|||||||
|
|
||||||
export const useAuth = createMiddleware(async (req, res, next) => {
|
export const useAuth = createMiddleware(async (req, res, next) => {
|
||||||
const token = getAuthToken(req);
|
const token = getAuthToken(req);
|
||||||
const key = parseSecureToken(token, secret());
|
const payload = parseSecureToken(token, secret()) || {};
|
||||||
const shareToken = await parseShareToken(req);
|
const shareToken = await parseShareToken(req);
|
||||||
|
|
||||||
let user;
|
let user;
|
||||||
|
const { userId, key } = payload;
|
||||||
|
|
||||||
if (validate(key)) {
|
if (validate(userId)) {
|
||||||
user = await getUser({ id: key });
|
user = await getUser({ id: userId });
|
||||||
} else if (redis.enabled) {
|
} else if (redis.enabled) {
|
||||||
user = await redis.get(key);
|
user = await redis.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log({ token, payload, user, shareToken });
|
||||||
|
|
||||||
if (!user && !shareToken) {
|
if (!user && !shareToken) {
|
||||||
log('useAuth:user-not-authorized');
|
log('useAuth:user-not-authorized');
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
log({ user, token, shareToken, key });
|
|
||||||
|
|
||||||
req.auth = { user, token, shareToken, key };
|
req.auth = { user, token, shareToken, key };
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user