klmn
TTCTheo's Typesafe Cult
•Created by klmn on 10/9/2023 in #questions
Nestjs not returning the body of the request using @Body decorator
This code
@Post('signup')
signup(@Body() dto: AuthDto) {
console.log('Received DTO + :', dto);
return dto;
}
where AuthDto defines the type
export class AuthDto {
public email: string;
public name: string;
public password: string;
}
is logging and returning an empty object when called to signup endpoint with body
{
"email": "[email protected]",
"name": "Test User",
"password": "password123"
}
However, this code works just fine
@Post('signup')
signup(
@Body('email') email: string,
@Body('name') name: string,
@Body('password') password: string,
) {
return {email, name, password};
}
What could be the reason?
2 replies