Passport.js: how to access user object after authentication?

Late to the party but found this unanswered after googling the answer myself.

Inside the request will be a req.user object that you can work withr.

Routes like so:

app.get('/api/portfolio', passport.authenticate('jwt', { session: false }), stocks.buy);

Controller like this:

buy: function(req, res) {
      console.log(req.body);
      //res.json({lel: req.user._id});
      res.json({lel: req.user});
    }

Leave a Comment