Passport authenticate callback is not passed req and res

前端 未结 2 1612
太阳男子
太阳男子 2021-01-02 01:26

this authenticate works fine and I get a redirect:

server.post(authPostRoute, passport.authenticate(
    \'local\'
    , { successRedirect: \'/\', failureRed         


        
2条回答
  •  伪装坚强ぢ
    2021-01-02 02:20

    OK, I was working on ripping out my custom authentication and replacing it with passport for 9 hours yesterday. Between getting the node-orm to expos the model outside of the request and dealing with the flow of ordering things I was a little burned out. THe code examples are accurate, I just needed to read more carefully:

    // traditional route handler, passed req/res
    server.post(authPostRoute, function(req, res, next) {
    
      // generate the authenticate method and pass the req/res
      passport.authenticate('local', function(err, user, info) {
        if (err) { return next(err); }
        if (!user) { return res.redirect('/'); }
    
        // req / res held in closure
        req.logIn(user, function(err) {
          if (err) { return next(err); }
          return res.send(user);
        });
    
      })(req, res, next);
    
    });
    

提交回复
热议问题