#Endpoint Returning Undefined Token
1 messages · Page 1 of 1 (latest)
We tried using a DTO here, that only had token: string; but that failed too. It wasn't until we dropped the DTO and went with string that we actually got the errors.
// route: /account
@Controller('account')
export class AccountController {
constructor(private accountService: AccountService) {}
// route: /account/:token
@UseGuards(JWTGuard)
@Post('/:token')
accountRetrieve(
@Param(':token') token: string,
@Request() req,
@Res({ passthrough: true }) res
) {
console.log('token', data);
return this.accountService.retrieve(token, req, res);
}
}
We tried also sending the token in the body, but didn't get anywhere with it.
// route: /account/:token
@UseGuards(JWTGuard)
@Post()
accountRetrieve(@Body() data: string) {
console.log('token', data);
return this.accountService.retrieve(data);
}
Before anyone asks, we have other endpoints using the @Param method with dynamic data. It works just fine. The only difference here is that we don't have any other data being sent in the body.
// route: /account/password-reset/:id
@Patch('password-reset/:token')
accountPasswordReset(
@Param(':token') token: string,
@Body() data: AccountPasswordResetDTO,
@Request() req,
@Res({ passthrough: true }) res
) {
return this.accountService.passwordReset(token, data, req, res);
}
When I use this method, using the DTO, here is the error. This errors before any code is executed, and there are no console errors.
{
"statusCode": 400,
"message": [
"token must be a string"
],
"error": "Bad Request"
}
When the DTO is removed and replace with string, we get the below error.