Skip to content

Instantly share code, notes, and snippets.

@brenttimmermans
Last active June 28, 2019 09:00
Show Gist options
  • Save brenttimmermans/69940123469cddf7811611705ada00f4 to your computer and use it in GitHub Desktop.
Save brenttimmermans/69940123469cddf7811611705ada00f4 to your computer and use it in GitHub Desktop.
Extract properties from JSON Web Token body
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