Permissions authorization middleware.

This commit is contained in:
Ahmed Bouhuolia
2019-09-16 01:08:19 +02:00
parent ed4d37c8fb
commit de905d7e7c
23 changed files with 318 additions and 51 deletions

View File

@@ -1,4 +1,16 @@
const authorization = (req, res, next) => {
/* eslint-disable consistent-return */
const authorization = (resourceName) => (...permissions) => (req, res, next) => {
const { user } = req;
};
const onError = () => {
res.boom.unauthorized();
};
user.hasPermissions(resourceName, permissions)
.then((authorized) => {
if (!authorized) {
return onError();
}
next();
}).catch(onError);
};
export default authorization;