Last active
May 30, 2018 23:20
-
-
Save AntonioErdeljac/e78af14bb27bb63ebdd1ab9fb8e29bd5 to your computer and use it in GitHub Desktop.
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
const jwt = require('express-jwt'); | |
const getTokenFromHeaders = (req) => { | |
const { headers: { authorization } } = req; | |
if(authorization && authorization.split(' ')[0] === 'Token') { | |
return authorization.split(' ')[1]; | |
} | |
return null; | |
}; | |
const auth = { | |
required: jwt({ | |
secret: 'secret', | |
userProperty: 'payload', | |
getToken: getTokenFromHeaders, | |
}), | |
optional: jwt({ | |
secret: 'secret', | |
userProperty: 'payload', | |
getToken: getTokenFromHeaders, | |
credentialsRequired: false, | |
}), | |
}; | |
module.exports = auth; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment