Reputation: 33974
I am trying to decode JSON web token but it returns null. I even tried with complete set to true but still it fails.
Function used to generate token:
import jwt from 'jsonwebtoken';
jwt.sign({ id: 5a2fa889c546431ccc5692e1,
firstName: 'hemadri',
lastName: 'dasari',
email: '[email protected]',
role: 'Member',
sex: 'male',
dob: undefined,
authenticated: true }, "pemmasaniDasari")
{token:
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjVhMmZhODg5YzU0NjQzMWNjYzU2OTJlMSIsImZpcnN0TmFtZSI6ImhlbWFkcmkiLCJsYXN0TmFtZSI6ImRhc2FyaSIsImVtYWlsIjoiaGVtYWRyaS5kYXNhcmkxOTkwQGdtYWlsLmNvbSIsInJvbGUiOiJNZW1iZXIiLCJzZXgiOiJtYWxlIiwiYXV0aGVudGljYXRlZCI6dHJ1ZSwiaWF0IjoxNTE0MzQyNDQ0fQ.LRMJXUvW7TdPdpoet53Wm6SQYX3VuNYZ_wJHfujbxfY"}
version: "jsonwebtoken": "^8.1.0"
Function that I used to decode is:
jwt.decode(token)
Upvotes: 0
Views: 1621
Reputation: 33974
The issue was while generating token I have appended few characters to it (you can see that in the start of the token) i.e., JWT in my Original Post. Which was actually causing an issue. I am able to decode it now post removing JWT from the token.
Upvotes: 2