Created
October 7, 2018 02:04
-
-
Save kidap/65e67e6446735cecfd0600b348fd2306 to your computer and use it in GitHub Desktop.
auth.js
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; |
Author
kidap
commented
Oct 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment