刚开始看到这个错误。
我知道这与这里的问题有关:Using jwt-decode with typescript front-end project
然而,我已经在尝试答案,它不工作...
x1c 0d1x的数据
代码
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;
}
字符串
错误
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)`
型
注意事项:我在一个react项目中使用了相同的代码片段,它工作得很好。然而,这似乎在我的react-native/expo项目中中断了。不确定这是否是一个dom相关的问题,或者是什么问题。有替代的解决方案吗?
1条答案
按热度按时间cdmah0mi1#
https://github.com/auth0/jwt-decode/blob/main/CHANGELOG.md#migration-to-v400
迁移到v4.0.0
jwtDecode
函数现在不再是默认导出,而是作为命名导出提供。请确保在导入此函数的地方更新代码:字符串