[HowTo 🎓] Finally create proper lifecycle hooks for users(-permissions)


It doesn’t get stuck, it’s just that my code is not being called (aka: I don’t see my console log)

And this is the code I used in “strapi-server” (basically yours, I just changed the methods to only generate create and update lifecycles)

const controllers = plugin.controllers.user;
  const methods = ['create', 'update'];
  console.log("applying lifecycle for users")
  for (const method of methods) {
    const oldMethod = controllers[method];

    controllers[method] = async (ctx) => {
      console.log(`before${method[0].toUpperCase() + method.slice(1)}`)
      await hooks[`before${method[0].toUpperCase() + method.slice(1)}`](ctx);
      const result = await oldMethod(ctx);
      await hooks[`after${method[0].toUpperCase() + method.slice(1)}`](ctx);
      return result;
    };
  }