mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-27 12:55:45 +01:00
19 lines
544 B
TypeScript
19 lines
544 B
TypeScript
import { NextApiRequestAuth } from 'lib/types';
|
|
import { useAuth } from 'lib/middleware';
|
|
import { NextApiResponse } from 'next';
|
|
import { badRequest, ok } from 'next-basics';
|
|
import redis from '@umami/redis-client';
|
|
import { setAuthKey } from 'lib/auth';
|
|
|
|
export default async (req: NextApiRequestAuth, res: NextApiResponse) => {
|
|
await useAuth(req, res);
|
|
|
|
if (redis.enabled && req.auth.user) {
|
|
const token = await setAuthKey(req.auth.user, 86400);
|
|
|
|
return ok(res, { user: req.auth.user, token });
|
|
}
|
|
|
|
return badRequest(res);
|
|
};
|