Additional params to Lifecycles Events

System Information
  • Strapi Version: 4
  • Operating System: Windows 10
  • Database: Maria DB
  • Node Version: 16
  • NPM Version: 8
  • Yarn Version:

Is there any way to pass additional params to lifecycles events without using the Query Engine API or overriding the Entity Service?

I’m using heavily lifecycles hooks to let the admin perform the same operations as the user (for example creating an entity on the admin performs a POST request on another server).
Is there any different approach to what I’m doing?

I’m currently working on this for a V3 version which is station to station.
So you can do Create, Update without overriding anything by creating a plugin and send post request then handle it.
But for Delete, publish and unpublish I had to override the entity-service in Content-manager to send more data (it normally just sent publish / unpublish the published_at field) and I added a uuid to have something unique.

Not sure if it’s the same idea but have a look at the talk here ?

That was really interesting but it won’t solve my problem.

I need to pass some params that I have on the controller (for example the session that I have from the authentication) to the lifecycle event to POST to other servers using the authenticated user session.

If you have access to it in the controller then pass it to a service, collect it there then send it forward again etc if needed?

Yes that’s what I’m doing right now but the problem si at service level where I have to use the Query Engine API to pass custom params to the lifecycle hook and that’s the problem because doing so I’m not using the Entity Service and I cannot upload images or edit components and dynamic zones.

I’m doing like this:

strapi.db.query(uid).findOne({
  where: {
    id: 12345
  },
  customParam: true
});

and in lifecycles.js i can do:

beforeFindOne(event) {
  const customParam = event.params.customParam;
}