import { createParamDecorator, ExecutionContext } from '@nestjs/common'; /** * Set a flag on the route handler to indicate that the user's * roles should be checked before the handler is invoked. * @returns CustomDecorator */ export const User = createParamDecorator( (field: string | null = null, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest(); if (!request.auth || !request.auth.user) { return null; } return field ? request.auth.user[field] : request.auth.user; } );