Last active
June 17, 2019 23:21
-
-
Save dmmulroy/a0e3393ca8e432b6fc4eb1d49ca2da59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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('jsonwebtoken'); | |
const config = require('../../config'); | |
module.exports = (req, res, next) => { | |
try { | |
const [_, token] = req.get('Authorization').split(' '); | |
if (!token) return res.status(401).end(); | |
const decodedToken = jwt.verify(token, config.JWT_SECRET, { | |
issuer: config.JWT_ISSUER | |
}); | |
if (!decodedToken) { | |
return res.status(403).end(); | |
} | |
req.decodedToken = decodedToken; | |
return next(); | |
} catch (err) { | |
console.error(err); | |
return res.status(401).end(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment