Currently utilizing jsonwebtoken
for token decoding purposes and attempting to retrieve the expiration date. Encountering TypeScript errors related to the exp
property, unsure of the solution:
import jwt from 'jsonwebtoken'
const tokenBase64 = 'ey...' /* some valid token */
const token = jwt.decode(tokenBase64)
const tokenExpirationDate = token.exp
// ^^^
// Property 'exp' does not exist on type 'string | object'. Property 'exp' does not exist on type 'string'.
Installed @types/jsonwebtoken
, but unable to find a proper token type for casting token
. Any suggestions?
Utilizing
@types/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df7eef2f3eaf8ffe9f2f6f8f3ddaab3afb3ae">[email protected]</a>
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="771d04181900121503181c1219374f59465947">[email protected]</a>
.tsconfig:
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"jsx": "Preserve",
"moduleResolution": "Node",
"module": "ESNext",
"sourceMap": true,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"target": "ESNext"
}
}