Backend/auth/token_validation.js
2022-01-13 19:22:20 +05:30

32 lines
808 B
JavaScript

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_SECRET_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"
})
}
}
}