How to redirect to unauthenticated user using express-jwt How to redirect to unauthenticated user using express-jwt express express

How to redirect to unauthenticated user using express-jwt


If user is not authenticated error is thrown and node.js stops code execution. After that you would be able to catch it in express error handler:

  app.use(function(err, req, res, next) {    if(401 == err.status) {        res.redirect('/home')    }  });