mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +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
|
|
@ -1,22 +1,8 @@
|
|||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, unauthorized } from 'next-basics';
|
||||
import redis from 'lib/redis';
|
||||
import { secret } from 'lib/crypto';
|
||||
import { getAuthToken } from 'lib/auth';
|
||||
import { ok } from 'next-basics';
|
||||
|
||||
export default async (req, res) => {
|
||||
if (redis.enabled) {
|
||||
const token = await getAuthToken(req, secret());
|
||||
const user = await redis.get(token);
|
||||
await useAuth(req, res);
|
||||
|
||||
return ok(res, user);
|
||||
} else {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.auth) {
|
||||
return ok(res, req.auth);
|
||||
}
|
||||
}
|
||||
|
||||
return unauthorized(res);
|
||||
return ok(res, req.auth);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue