Get user identity inside lifeCycle hook

Hi, not sure if you still face this issue but this is what I use.

export default ({ strapi }: { strapi }) => {
  strapi.db.lifecycles.subscribe((<Subscriber>{
    async afterFindOne(event): Promise<void> {
      // Get the request config
      const ctx = strapi.requestContext.get();

      console.log(ctx?.state?.user);
    },
  }) as Subscriber);
}

Documentation can be found here: Requests and Responses - Strapi Developer Docs

4 Likes