I am using passport JwtStrategy to validate token in my project, but it is sending same error message "Unauthorized" for every errors
If the token expired also it is sending "Unauthorized" status only but I need to get token expired status
Is there any way to implement this logic
const passport = require("passport")
const JwtStrategy = require("passport-jwt").Strategy,
ExtractJwt = require("passport-jwt").ExtractJwt
const opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken()
opts.secretOrKey = JWT_SECRET
passport.use(
new JwtStrategy(opts, function (jwt_payload, done) {
UserID.findOne({ id: jwt_payload._id }, function (err, id) {
if (err) {
return done(err, false)
}
if (id) {
return done(null, id)
} else {
return done(null, false)
}
})
})
)