API/api.medcify.app/auth/token_validation.js

32 lines
801 B
JavaScript
Raw Permalink Normal View History

2022-09-26 06:11:44 +00:00
const { verify } = require('jsonwebtoken');
module.exports={
checkToken : (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":"This mobile number is register on another device please check"
})
}
else
{
next();
}
});
}
else
{
res.json({
"success":"0",
"message":"Unauthorized user Credentials"
})
}
}
}