question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Policy beforeAll not called in production mode

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cxl-toddcommented, Sep 11, 2020

Hey @mblarsen, looks good to me! Thanks!

0reactions
mblarsencommented, Sep 11, 2020

Hi @cxl-todd I appended a section to the README setup section what do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

@BeforeAll and @AfterAll in Non-Static Methods | Baeldung
We'll use the @TestInstance annotation to configure the lifecycle of a test. If we don't declare it on our test class, the lifecycle...
Read more >
scala - Little confused on the usefulness of beforeAll construct ...
I have more of a philosophical confusion in-regards to the usefulness of methods like 'beforeAll' in scalaTest. I have been looking for an ......
Read more >
beforeAll: not skipped within describe.skip #6166 - GitHub
Define a beforeAll inside the describe.skip block. ... It seems there's currently no logic checking whether it should be executed or not.
Read more >
Testing Your Application - Quarkus
Learn how to test your Quarkus Application. This guide covers: Testing in JVM mode. Testing in native mode. Injection of resources into tests ......
Read more >
Preface to A Contribution to the Critique of Political Economy
The mode of production of material life conditions the general process of social, ... No social order is ever destroyed before all the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found