You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
538 B
27 lines
538 B
import { NextApiHandler } from "next";
|
|
|
|
import { withIronSession } from "@utils/session";
|
|
import { methodNotAllowed, unauthorized } from "@utils/errors";
|
|
|
|
const handle: NextApiHandler = (req, res) => {
|
|
if (req.method?.toUpperCase() != "GET") {
|
|
res.status(405).json(methodNotAllowed);
|
|
return;
|
|
}
|
|
|
|
const user = req.session.user;
|
|
|
|
if (user === undefined) {
|
|
res.status(401).json(unauthorized);
|
|
return;
|
|
}
|
|
|
|
req.session.destroy();
|
|
|
|
req.session.user = undefined;
|
|
|
|
res.redirect("/blog");
|
|
};
|
|
|
|
export default withIronSession(handle);
|