umami/pages/api/auth/sso.ts

19 lines
544 B
TypeScript
Raw Normal View History

2023-04-05 08:29:54 +02:00
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);
};