DEV Community

Cover image for Bad Request in nestjs, help me!
ALAN MARTINS AGUIAR
ALAN MARTINS AGUIAR

Posted on

2 1

Bad Request in nestjs, help me!

guys, how are you? I have a problem with the refresh token request it says it's a bad request.
My code can store the login token in the database but I can't make the Put request through the refreshToken function.
from what I understand I think my controller is wrong, because I send it through postman and I already tried to send valid, invalid and token that does not exist and all the request gives the same error, in theory it was for the non-existing token to send my response "invalid token" with was handled in refreshToken function.
I did the same procedure, I copied and pasted the same token there in my database.

@Put('refresh')
async refreshToken(@Body() data: RefreshTokenDto) {
return this.tokenService.refreshToken(data.oldToken);
}
async refreshToken(oldToken: string) {
const objToken = await this.findOneRefreshToken(oldToken);
console.log(objToken);

if (objToken) {
  return await oldToken;
} else {
  return new HttpException(
    {
      errorMessage: 'Token inválido',
    },
    HttpStatus.UNAUTHORIZED,
  );
}
Enter fullscreen mode Exit fullscreen mode

}
{
"statusCode": 400,
"message": [
"property oldToken should not exist"
],
"error": "Bad Request"
}
async findOneRefreshToken(hash: string) {
return await this.prisma.token.findUnique({
where: {
hash,
},
});
}
Note: I'm using prism and nestjs

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay