1import jwt_decode from "jwt-decode";
2var token = "eyJ0eXAiO...";
3var decoded = jwt_decode(token);
4console.log(decoded);
5
6/* prints: * { foo: "bar", * exp: 1393286893, * iat: 1393268893 } */
1let b64DecodeUnicode = str =>
2 decodeURIComponent(
3 Array.prototype.map.call(atob(str), c =>
4 '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
5 ).join(''))
6
7let parseJwt = token =>
8 JSON.parse(
9 b64DecodeUnicode(
10 token.split('.')[1].replace('-', '+').replace('_', '/')
11 )
12 )
1import jwt_decode from "jwt-decode"; var token = "eyJ0eXAiO.../// jwt token";var decoded = jwt_decode(token); console.log(decoded); /* prints: * { foo: "bar", * exp: 1393286893, * iat: 1393268893 } */ // decode header by passing in options (useful for when you need `kid` to verify a JWT):var decodedHeader = jwt_decode(token, { header: true });console.log(decodedHeader); /* prints: * { typ: "JWT", * alg: "HS256" } */