Created
February 12, 2019 18:24
-
-
Save LB-Digital/17b41286f66ee48e7c78ab0d957efd99 to your computer and use it in GitHub Desktop.
Retrieve the Payload data section of a JSON Web Token.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getJwtPayload(){ | |
//retrieve JsonWebToken from cookies | |
var cookies = document.cookie.split(";"), | |
jwt; | |
for (cookie of cookies){ | |
var keyValue = cookie.trim().split('='); | |
if (keyValue[0] === "jwt"){ | |
jwt = keyValue[1]; | |
} | |
} | |
//extract user data from JsonWebToken | |
var payload = jwt.split('.')[1]; // middle section = payload | |
var decodedPayload = JSON.parse(atob(payload)); | |
return decodedPayload['data']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment