Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jwt-decode with typescript front-end project

Description I am trying to use jwt-decode in a typescript project i.e. Stencil Project & it is throwing following error:

This expression is not callable.Type '{ default: (token: string, options?: Options) => TTokenDto; }' has no call signatures.

import * as jwt_decode from 'jwt-decode';
.
.
.
let token = "........";
let decoded = jwt_decode(token);

Reproduction

  • install jwt-decode in any typescript project npm install --save @types/jwt-decode npm install --save jwt-decode import it in your code & use import * as jwt_decode from 'jwt-decode'; . . . let token = "........"; let decoded = jwt_decode(token);
  • build project
  • Version of this library used: ^2.2.0 Version of the platform or
  • framework used, if applicable: stencil - ^1.3.3 , typescript - 3.7.2
like image 624
Rahul Bhooteshwar Avatar asked Dec 11 '19 07:12

Rahul Bhooteshwar


People also ask

Should I decode JWT in frontend?

JWT decode only look for public part so it is totally safe to do that in your front-end code. Save this answer.


1 Answers

Following correction to the import statement works fine:

import jwt_decode from 'jwt-decode';
like image 164
Rahul Bhooteshwar Avatar answered Oct 22 '22 17:10

Rahul Bhooteshwar