all setup with jwt and bcrypt with whole file structure with auth middleware and login
This commit is contained in:
@@ -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'
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user