API/api.medcify.app/helper/authverify.js
2022-09-26 11:41:44 +05:30

33 lines
732 B
JavaScript

const { verify } = require('jsonwebtoken');
module.exports = {
authVerify: (req, res, next) => {
let token = req.get('authorization');
if (token) {
token = token.slice(7);
verify(token, process.env.JWT_KEY, (err, decoded) => {
if (err) {
res.json({
"Code": "2",
"Message": "Unauthorized Credentials"
})
}
else {
next();
}
});
}
else {
res.json({
"success": "0",
"message": "Unauthorized user Credentials"
})
}
}
}