Policy beforeAll not called in production mode
See original GitHub issueI’ve run into a strange issue where I’ve defined all my rules in a policy and applied that to various targets in a plugin definition. This appears to install well enough and executes most of the code. However, the beforeAll
function, while executing in NODE_ENV=development
does nothing when executing in NODE_ENV=production
. I cannot nail it down. Here are some snippets from the plugin source:
export default ({ app, store }) => {
const getUser = () => {
console.log('--> In acl.getUser');
if (!app.$auth.loggedIn) {
console.log('----> In acl.getUser: user is NOT logged in');
return {};
}
console.log('----> In acl.getUser: user is logged in');
return app.$auth.user;
}
class PermissionBasedPolicy {
beforeAll(verb, user, target, targetId) {
console.log(`------> In acl.beforeAll: user ${user.id}, verb ${verb}, target ${target}, targetId ${targetId}`);
return permissionMatcher(store, verb, user, target, targetId);
}
}
class Foo {}
class Bar {}
Vue.use(Acl, getUser, (acl) => {
acl.policy(PermissionBasedPolicy, Foo);
acl.policy(PermissionBasedPolicy, Bar);
}, {
helper: true,
});
Vue.prototype.$can.any = (verbs, verbObjects, ...args) => {
console.log('In acl.$can.any');
return verbs.some(verb => Vue.prototype.$can(verb, verbObjects, ...args));
};
};
When in development mode all prints to console as intended:
In acl.$can.any
--> In acl.getUser
----> In acl.getUser: user is logged in
------> In acl.beforeAll: user e5da3cf2-242a-11e8-b467-0ed5f89f718b, verb WRITE, target Foo, targetId Foo
--> In acl.getUser
----> In acl.getUser: user is logged in
------> In acl.beforeAll: user e5da3cf2-242a-11e8-b467-0ed5f89f718b, verb ALL, target Foo, targetId Foo
When in production mode - and I can’t stress enough that this is the only explicit change I am making - it never hits the beforeAll
as evidenced by the same logging statements’ output:
...
In acl.$can.any
--> In acl.getUser
----> In acl.getUser: user is logged in
--> In acl.getUser
----> In acl.getUser: user is logged in
...
I am running this from within a nuxtjs application. As such, building in production mode has some side effects related to webpack, etc. A lot of that is beyond my expertise, but it seems extremely odd that a function call is completely omitted.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hey @mblarsen, looks good to me! Thanks!
Hi @cxl-todd I appended a section to the README setup section what do you think?