I made function like this, that should check if module is forbidden for current user. If it is - return error, if not - then let him do rest of hooks/proceed to api route. This method is called in service hooks.
function isAppForbidden(hook) {
return new Promise((resolve, reject) => {
hook.app.services.settings.find({
query: {
$limit: 1,
$sort: {
createdAt: -1
}
},
user: {
roleId: hook.params.user.roleId
}
}).then(res => {
if(res.data.length > 0) {
let userHiddenApps = hook.params.user.hiddenApps || [];
let globalHiddenApps = res.data[0].forbiddenApps || [];
if (userHiddenApps.indexOf('qualitydocs') >= 0 || globalHiddenApps.indexOf('qualitydocs') >= 0) {
reject(new errors.Forbidden()); //throws error for forbidden moduels
}
resolve();
}
})
})
}
before: {
all: [
authenticate('jwt'),
hook => includeBefore(hook),
hook => isAppForbidden(hook)
],
find: [],
get: [],
create: [(hook) => {
hook.data.authorId = hook.params.user.id;
}],
update: [],
patch: [],
remove: []
},
On my local machine everything works just fine. If module is forbiden I get Forbiden error, if not then I get data from route. But on my production machine it doesnt work that way, if module is NOT forbidden (no error) I fail to receive any response as if it ended up in some kind of loop on 'resolve()' part?? Is it possible? does this promise look fine to you?
I know its weird question but i have no clue where to start since it works perfectly fine locally and no errors on production (except it breaks whole app, no responses anymore, till you reload page).