Skip to content

Commit

Permalink
fix(Decode Authroization): Parse JWT token by removing prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaalpuerto committed Jul 25, 2018
1 parent a0198b3 commit 26a307c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/infra/jwt/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const jwt = require('jsonwebtoken')
const {
compose,
trim,
replace,
partialRight
} = require('ramda')

module.exports = ({ config }) => ({
signin: (options) => (payload) => {
Expand All @@ -11,6 +17,12 @@ module.exports = ({ config }) => ({
},
decode: (options) => (token) => {
const opt = Object.assign({}, options)
return jwt.verify(token, opt)
const decodeToken = compose(
partialRight(jwt.decode, [opt]),
trim,
replace(/JWT|jwt/g, '')
)

return decodeToken(token)
}
})

0 comments on commit 26a307c

Please sign in to comment.