umami/pages/api/auth/logout.ts
2022-11-15 13:21:14 -08:00

20 lines
486 B
TypeScript

import { methodNotAllowed, ok } from 'next-basics';
import { useAuth } from 'lib/middleware';
import redis from 'lib/redis';
import { getAuthToken } from 'lib/auth';
import { NextApiRequest, NextApiResponse } from 'next';
export default async (req: NextApiRequest, res: NextApiResponse) => {
await useAuth(req, res);
if (req.method === 'POST') {
if (redis.enabled) {
await redis.del(getAuthToken(req));
}
return ok(res);
}
return methodNotAllowed(res);
};