According to documentation, https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback, jwt.verify
will returns decode payload, I run the simple script:
var token = jwt.sign({email: req.body.email,}, 's3cr3t');
var decoded = jwt.verify(token, 's3cr3t');
console.log(decoded)
but it only output like: { iat: 1470725598 }
I expect the output should be like {email: [email protected],}
Is there something I am missing ?
jwt.verify(token, secretOrPublicKey, [options, callback]) (Synchronous) If a callback is not supplied, function acts synchronously. Returns the payload decoded if the signature is valid and optional expiration, audience, or issuer are valid. If not, it will throw the error.
iat" (Issued At) Claim The "iat" (issued at) claim identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.
JWTs are mainly used for authentication. After a user signs in to an application, the application then assigns JWT to that user. Subsequent requests by the user will include the assigned JWT. This token tells the server what routes, services, and resources the user is allowed to access.
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.
I was not able to mimic your problem until I set the property req.body.email
to undefined
.
Example:
var jwt = require('jsonwebtoken');
var token = jwt.sign({email: undefined}, 's3cr3t');
var decoded = jwt.verify(token, 's3cr3t');
With it been undefined, the output would look like this;
{ iat: 1470727340 }
and this matches exactly what you were having which cause me to suspect your main issue was just with the property req.body.email
been undefined
.
Assuming req.body.email
is correctly set to "[email protected]" then the output would be;
{ email: '[email protected]', iat: 1470727500 }
Just a side note here. You might want to consider wrapping the .verify
method inside a try-catch
clause, as shown in the documentation. This is useful for verifying and throwing error when a token is invalid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With