# All files / modules/auth/decorators current-user.decorator.ts

28.57% Statements 2/7
0% Branches 0/3
0% Functions 0/1
28.57% Lines 2/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    169x

    9x

     import { createParamDecorator, ExecutionContext } from '@nestjs/common';
    import { RequestUser } from '../strategies/jwt.strategy';

    export const CurrentUser = createParamDecorator(
      (data: keyof RequestUser | undefined, ctx: ExecutionContext) => {
        const request = ctx.switchToHttp().getRequest();
        const user = request.user as RequestUser;

        Iif (!user) {
          return null;
        }

        return data ? user[data] : user;
      },
    );