mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
Permissions authorization middleware.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user