This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Biblio/utils/requirePermission.js

13 lines
405 B
JavaScript
Raw Permalink Normal View History

'use strict';
// Adapted from https://stackoverflow.com/questions/9609325/node-js-express-js-user-permission-security-model
module.exports = function requirePermission(permission) {
return function(req, res, next) {
console.log(req.user);
if (req.user && req.user.permissions[permission]) {
next();
} else {
res.status(403).send(`Permission ${permission} not met.`);
}
}
}