From b91bb0a133aa3d0400beb359fed4e641c888ab26 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 31 Oct 2022 22:40:42 +0100 Subject: Added logout route, and a way to display the logout menu item on relevant pages --- routes/logout.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 routes/logout.js (limited to 'routes/logout.js') diff --git a/routes/logout.js b/routes/logout.js new file mode 100644 index 0000000..a31d9fe --- /dev/null +++ b/routes/logout.js @@ -0,0 +1,15 @@ +import express from "express"; + +import session from "../middlewares/sessions.js"; + +const router = express.Router(); +router.use(session); + +router.get("/", (req, res) => { + if (req.session.user !== undefined) { + req.session.destroy(); + } + return res.redirect(302, "/"); +}); + +export default router; -- cgit v1.2.3