mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
23 lines
516 B
JavaScript
23 lines
516 B
JavaScript
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';
|
|
|
|
export default async (req, res) => {
|
|
if (redis.enabled) {
|
|
const token = await getAuthToken(req, secret());
|
|
const user = await redis.get(token);
|
|
|
|
return ok(res, user);
|
|
} else {
|
|
await useAuth(req, res);
|
|
|
|
if (req.auth) {
|
|
return ok(res, req.auth);
|
|
}
|
|
}
|
|
|
|
return unauthorized(res);
|
|
};
|