Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/middlewares/sessionCheck.js

15 lines
461 B
JavaScript
Raw Normal View History

function sessionCheck(permission) {
return (req, res, next) => {
if (!req.session.user) {
req.session.lastUrl = req.originalUrl;
req.session.save(() => res.redirect("/login"));
2020-08-18 15:45:49 +02:00
} else if (req.session.user.permissions < permission) {
res.status(403);
res.render("error", {message: "Permission denied !", "error": {}});
2020-08-18 15:45:49 +02:00
} else
next();
}
}
module.exports = sessionCheck;