Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it in node typescript applicaiton #52

Closed
yhjhoo opened this issue Jun 21, 2017 · 7 comments
Closed

How to use it in node typescript applicaiton #52

yhjhoo opened this issue Jun 21, 2017 · 7 comments
Labels
closed:stale Issue or PR has not seen activity recently

Comments

@yhjhoo
Copy link

yhjhoo commented Jun 21, 2017

what should I do after the following

var jwtDecode = require('jwt-decode');

I am very new to typescript and node

@DavidRutqvist
Copy link

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

@ignatzami
Copy link

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.

@DevanB
Copy link

DevanB commented Dec 17, 2018

@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 🤷‍♂️

@ashpreetbedi
Copy link

@DevanB Were you able to figure this out?

@RiJung
Copy link

RiJung commented Jan 23, 2019

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);
}

@stale
Copy link

stale bot commented Oct 26, 2019

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! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Oct 26, 2019
@stale stale bot closed this as completed Nov 2, 2019
@mahdipakravan-dev
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:stale Issue or PR has not seen activity recently
Projects
None yet
Development

No branches or pull requests

7 participants