Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jwt-decode "This expression is not callable." with typscript

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...

enter image description here

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?

like image 563
Fiddle Freak Avatar asked Mar 21 '26 17:03

Fiddle Freak


1 Answers

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";
like image 167
Vasyl Nahuliak Avatar answered Mar 23 '26 06:03

Vasyl Nahuliak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!