umami/pages/api/auth/logout.js
2022-11-08 22:58:52 -08:00

19 lines
397 B
JavaScript

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