JwtDecode function for reading content of jwt token.

This commit is contained in:
2020-01-10 23:28:45 +01:00
parent f2a65d755c
commit c16543099e

View File

@@ -7,7 +7,17 @@ const sortableSize = (string) => {
const exponent = UNITS.indexOf(unit) * 3
return numStr * (Math.pow(10, exponent))
}
};
const parseJwt = (token) => {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
};
export { sortableSize }
export { sortableSize, parseJwt }