Skip to content

Instantly share code, notes, and snippets.

@psynewave
Created August 26, 2020 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psynewave/a691db76861ee378dbee67d29c52e845 to your computer and use it in GitHub Desktop.
Save psynewave/a691db76861ee378dbee67d29c52e845 to your computer and use it in GitHub Desktop.
Decode JWT Client Side
const b64DecodeUnicode = (str) => decodeURIComponent(Array.prototype.map.call(atob(str),(c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join(""));
const parseJWT = (token) => JSON.parse(b64DecodeUnicode(token.split(".")[1].replace("-", "+").replace("_", "/")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment