DEV Community

Cover image for Decode JWT Token easily using _jwt-decode_
Nodirbek-Abdulaxadov
Nodirbek-Abdulaxadov

Posted on

Decode JWT Token easily using _jwt-decode_

  1. Install with NPM or Yarn
npm install jwt-decode
//or
yarn add jwt-decode
Enter fullscreen mode Exit fullscreen mode
  1. Import package:
import { jwtDecode } from "jwt-decode";
Enter fullscreen mode Exit fullscreen mode
  1. Usage
const token = "eyJ0eXAiO.../// jwt token";
// Returns with the JwtPayload type or any type
// const decodedJwt = jwtDecode<JwtPayload>(token);
const decodedJwt: any = jwtDecode(token);

//example print expiration date
console.log(decodedJwt.exp);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)