Giter Club home page Giter Club logo

Comments (7)

RiJung avatar RiJung commented on May 21, 2024 6

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.

DavidRutqvist avatar DavidRutqvist commented on May 21, 2024 5

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.

DevanB avatar DevanB commented on May 21, 2024 1

@ignatzami This is happening to me as well. Curious if this library is:

  1. Maintained still.
  2. 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.

ignatzami avatar ignatzami commented on May 21, 2024

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.

ashpreetbedi avatar ashpreetbedi commented on May 21, 2024

@DevanB Were you able to figure this out?

from jwt-decode.

stale avatar stale commented on May 21, 2024

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.

mahdipakravan-dev avatar mahdipakravan-dev commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.