Created
April 17, 2019 12:46
-
-
Save bayraktugrul/6bd7291b28ada7b3f42223dae58736b7 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('jsonwebtoken'); | |
module.exports = (req, res, next) => { | |
try { | |
/*JWT is send with request header! | |
Format of it: Authorization : Bearer <token> | |
*/ | |
const token = req.headers.authorization.split(" ")[1]; | |
const decodedToken = jwt.verify(token, 'secret_key'); | |
req.userData = decodedToken; | |
next(); | |
}catch(error) { | |
return res.status(401).send({ | |
message: 'Auth failed' | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment