nestjs-api-tutorial icon indicating copy to clipboard operation
nestjs-api-tutorial copied to clipboard

whitelist: true option not working for new ValidationPipe

Open moin-almin opened this issue 2 years ago • 1 comments

I have been trying to reproduce the validation part using dtos and global pipes but for some reason the whitelist option is not working. I know there have been ground breaking changes with nest, and their document hasn't been updated for the same, but the issue persists.

Here is my auth.dto.ts:

import { IsEmail, IsNotEmpty, IsString } from "class-validator"

export class AuthDto {
    @IsEmail()
    @IsNotEmpty()
    email: string;

    @IsString()
    @IsNotEmpty()
    password: string;
}

Here is my main.ts:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(new ValidationPipe({
    whitelist: true,
  }));
  await app.listen(3333);
}
bootstrap();

moin-almin avatar Sep 04 '23 18:09 moin-almin

did you solve it ?

Mohab-Rageh avatar Jul 17 '24 13:07 Mohab-Rageh