how to send json as a response after passport authenticationin node.js

后端 未结 6 473
日久生厌
日久生厌 2021-01-05 06:16

I am trying this git example.

Which works well when I integrated it with my project, but what I want to achieve is to send json as a response to the client/request,

6条回答
  •  一生所求
    2021-01-05 06:37

    There is an official Custom Callback documentation:

    app.get('/login', function(req, res, next) {
      passport.authenticate('local', function(err, user, info) {
        if (err) { return next(err); }
        if (!user) { return res.redirect('/login'); }
        req.logIn(user, function(err) {
          if (err) { return next(err); }
          return res.redirect('/users/' + user.username);
        });
      })(req, res, next);
    });
    

    https://github.com/passport/www.passportjs.org/blob/master/views/docs/authenticate.md

提交回复
热议问题