mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
17 lines
412 B
JavaScript
17 lines
412 B
JavaScript
/* 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;
|