Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How to check token expired or not in passportjs

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)
      }
    })
  })
)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!