NestJS – current auth user but not via decorator

I create belowed decorator to get current logged in to the system user,

export const CurrentUser = createParamDecorator(
    (data: unknown, ctx: ExecutionContext) => {
      const request = ctx.switchToHttp().getRequest();
      return request.user;
    },
  );

but I do not want to use this because i need to use in any of my controller
which is a bit troublesome for me because some functions are optional, i.e. both for the logged in user and the non logged in user,

so, how can I get current logged in user in my service in functions when i want to get current user instead of all via decorator in controller?

thanks for any help

Leave a Comment