This is how I am generating a JWT token
jwt.sign({}, 'a', {expiresIn: '30m'});
I send this token with every response. In the browser I am using the following code to decode the token.
//token is the complete JWT token generated by this module
let t = token.split('.')[1];
let exp = JSON.parse(atob(t)).exp
console.log(new Date(exp));
The exp is always set to 01/18/1970.
The expiry date is a NumericDate, which is the number of seconds since Epoch. Since Date takes milliseconds you need to multiply this by 1000.
So console.log(new Date(exp * 1000)) should show the correct date.
A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds. This is equivalent to the IEEE Std 1003.1, 2013 Edition [POSIX.1] definition "Seconds Since the Epoch", in which each day is accounted for by exactly 86400 seconds, other than that non-integer values can be represented. See RFC 3339 [RFC3339] for details regarding date/times in general and UTC in particular.
Missed that completely. Thanks a lot.
Most helpful comment
The expiry date is a
NumericDate, which is the number of seconds since Epoch. SinceDatetakes milliseconds you need to multiply this by1000.So
console.log(new Date(exp * 1000))should show the correct date.NumericDate