hiteshchoudhary / chai-backend

A video series on chai aur code youtube channel
4.69k stars 697 forks source link

JWT malformed #113

Open varghesetony901 opened 4 months ago

varghesetony901 commented 4 months ago

Error : JWT is malformed, when hitting the /refresh-token end point.

To resolve this change the code like this. const { accessToken, refreshToken } = await generateAccessAndRefereshTokens(user._id);

instead of const { accessToken, newRefreshToken } = await generateAccessAndRefereshTokens(user._id);

amanmalviya258 commented 4 months ago

newRefreshToken hi toh btaya hai bhai. check again

FahadBinQaiser commented 3 weeks ago

Error : JWT is malformed, when hitting the /refresh-token end point.

To resolve this change the code like this. const { accessToken, refreshToken } = await generateAccessAndRefereshTokens(user._id);

instead of const { accessToken, newRefreshToken } = await generateAccessAndRefereshTokens(user._id);

Do this instead

For those who are getting errors on the basis of jwt malformed do this,

Go to user.models.js Inside the file navigate to where you are generating your access and refresh tokens. Then simply inside it you have this jwt.sign( { } ) But you aren't returning it so it causes you the error.

Fix: return jwt.sign({}) In both access and refresh token generating.