Issue
Just started seeing this error.
I know this is related to the question here: Using jwt-decode with typescript front-end project
However, I already am trying the answer and it's not working...
The Code
import jwt from 'jwt-decode';
export function isTokenExpired(token: string): boolean {
// check token payload
const tokenPayload: any = jwt(token);
// check token expiration date in payload
const tokenExpiration = tokenPayload.exp;
const now = Math.floor(new Date().getTime() / 1000); // token exp shaved off milliseconds
// if (expiration date is greater than current date)
return now > tokenExpiration;
}
The Error
This expression is not callable.
Type 'typeof import("c:/Projects/msal-react-native-expo/node_modules/jwt-decode/build/cjs/index")' has no call signatures.ts(2349)`
Note: I'm using this same code snippet in a react project and it's working fine. However, this seems to be breaking in my react-native/expo project. Not sure if it's a dom related issue or what the deal is. Is there an alternative solution?
Solution
https://github.com/auth0/jwt-decode/blob/main/CHANGELOG.md#migration-to-v400
Migration to v4.0.0
The jwtDecode
function is now no longer the default export, and is instead provided as a named export. Make sure to update your code in places where you are importing this function:
-import jwtDecode from "jwt-decode";
+import { jwtDecode } from "jwt-decode";
Answered By - Vasyl Nahuliak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.