Skip to content

Instantly share code, notes, and snippets.

@AntonioErdeljac
Last active May 30, 2018 23:20
Show Gist options
  • Save AntonioErdeljac/e78af14bb27bb63ebdd1ab9fb8e29bd5 to your computer and use it in GitHub Desktop.
Save AntonioErdeljac/e78af14bb27bb63ebdd1ab9fb8e29bd5 to your computer and use it in GitHub Desktop.
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