I just don’t know where to search and don’t really understand why it’s not working
I have done everything from the doc. One things strange is that @Body is returning a function and not the body object.
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule, {cors: {origin: process.env.CORS_ORIGIN, credentials: true}});
app.use(cookieParser());
app.useGlobalPipes(new ValidationPipe({transform: true, whitelist: true}));
const configService = app.get(ConfigService);
const port = assertDefined(configService.get<string>('app.port'), 'Environment variable PORT is not defined');
await app.listen(port);
}
void bootstrap();
// register.dto.ts
import {IsEmail, IsString} from 'class-validator';
class RegisterDto {
@IsEmail()
@IsString()
email!: string;
@IsString()
username!: string;
@IsString()
password!: string;
}
export type {RegisterDto};
// auth.controller.ts
import {
Body,
Controller,
HttpCode,
HttpStatus,
Post,
} from '@nestjs/common';
import {AuthService} from './auth.service';
import {Public} from './decorators/public.decorator';
import {LoginDto} from './dtos/login.dto';
import {RegisterDto} from './dtos/register.dto';
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) { }
@Public()
@HttpCode(HttpStatus.OK)
@Post('login')
async login(@Body() loginDto: LoginDto) {
return this.authService.login(loginDto);
}
@Public()
@HttpCode(HttpStatus.CREATED)
@Post('register')
async register(@Body() registerDto: RegisterDto) {
return this.authService.register(registerDto);
}
}
I tried to wipe my dependencies but still the same.
I’m a bit lost
Thank you