Last active
June 28, 2019 09:00
-
-
Save brenttimmermans/69940123469cddf7811611705ada00f4 to your computer and use it in GitHub Desktop.
Extract properties from JSON Web Token body
This file contains hidden or 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
const jwtDecode = require('jwt-decode') | |
const { pick } = require('lodash') | |
/** | |
* Pick properties from JWT | |
* | |
* @param {String} token JSON Web Token | |
* @param {String || Array} props Single property (String) or multiple properties (Array) | |
* | |
* @returns Object containing all props | |
*/ | |
function extractFromToken (token, props = []) { | |
const decoded = jwtDecode(token) | |
return pick(decoded, props) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment