all setup with jwt and bcrypt with whole file structure with auth middleware and login

This commit is contained in:
Arjun Patel
2019-01-10 10:37:07 -08:00
parent 518840a576
commit 9f247154f9
10 changed files with 360 additions and 115 deletions
+15
View File
@@ -0,0 +1,15 @@
const jwt = require('jsonwebtoken');
module.exports = (req, res, next) => {
try {
const token = req.headers.authorization.split(' ')[1];
const decoded = jwt.verify(token, process.env.JWT_KEY);
req.donorData = decoded; //for use till end of request
next();
} catch (error) {
return res.status(401).json({
message: 'Auth failed'
});
}
};