Comments (7)
this works for me
import JwtDecode from 'jwt-decode';
export function checkExpired() {
const token = 'INSERT YOUR TOKEN HERE';
interface TokenDto {
foo: string;
exp: number;
iat: number;
}
interface TokenHeaderDto {
typ: string;
alg: string;
}
const decodedTokenPayloadOld = JwtDecode(token);
const decodedTokenPayload = JwtDecode<TokenDto>(token);
const decodedTokenHeaderOld = JwtDecode(token, { header: true });
const decodedTokenHeader = JwtDecode<TokenHeaderDto>(token, { header: true });
console.log('decodedTokenPayloadOld :', decodedTokenPayloadOld);
console.log('decodedTokenPayload :', decodedTokenPayload);
console.log('decodedTokenHeader :', decodedTokenHeader);
console.log('decodedTokenHeaderOld :', decodedTokenHeaderOld);
}
from jwt-decode.
I use it as such:
import * as jwtDecode from "jwt-decode";
and then e.g.
if (this.token && (jwtDecode(this.token).exp >= Math.floor(Date.now() / 1000)))
from jwt-decode.
@ignatzami This is happening to me as well. Curious if this library is:
- Maintained still.
- If not, what is a viable alternative to check the
exp
of a JWT.
I would assume Auth0 would maintain this, but 🤷♂️
from jwt-decode.
I'm working in TypeScript, and the return of jwt_decode is {} this is causing the following code to fail:
import jwt_decode from 'jwt-decode';
function getTokenExpirationDate(encodedToken: any) {
let token = jwt_decode(encodedToken);
if (!token.exp) { return null; }
const date = new Date(0);
date.setUTCSeconds(token.exp);
return date;
}
Specifically the token.exp field. I'm curious what type the return should be, and how I can force the typing in my application.
from jwt-decode.
@DevanB Were you able to figure this out?
from jwt-decode.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️
from jwt-decode.
Hi everyone i have problem when using jwt-decode package
when i use this package and implement my project i taked a bug names :
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
so i tryed again but i know this is actualy for this package , no one have a solution for me ?
from jwt-decode.
Related Issues (20)
- Thoughts on adding a bin? HOT 3
- Two additional tests? HOT 4
- jwtDecode is not a function HOT 3
- Does not work with electron packager/asar archive HOT 5
- ESM Support with Jest for Node Api clients HOT 2
- How about removing the atob polyfill? HOT 8
- Consider renaming `master` branch to `main` HOT 2
- Type definitions are broken in 4.0.0-beta.1 HOT 10
- Consider dropping Universal Module Definition (UMD) bundle HOT 4
- Yarn installing jwt-decode causes nx Daemon to crash HOT 4
- Using jwt-decode beta with node10 module resolution HOT 8
- InvalidTokenError: Invalid token specified: Unexpected number at position 0 HOT 3
- missing: https://unpkg.com/[email protected]/build/jwt-decode.js HOT 3
- v4.0.0 React Native support - property atob doesn't exist HOT 9
- No Support for React Native & Expo HOT 2
- Compatibility Issue with Node.js 16.18.1 on Expo Application Servers HOT 2
- React native decode HOT 1
- InvalidTokenError HOT 3
- jwt decode is not working in react native HOT 2
- jwtDecode is not working react native app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwt-decode.