passport local strategy not getting called

前端 未结 14 798
夕颜
夕颜 2020-12-13 04:31

I\'m sure I\'m missing something really obvious here, but I can\'t figure this out. The function I\'ve passed to the LocalStrategy constructor doesn\'t get called when the l

相关标签:
14条回答
  • 2020-12-13 05:04

    Hope it always someone - in my case it was the fact that I tried I used passport middleware before cookieParser and express-session ones This was my code:

    passportConfig(app);
    app.use(cookieParser());
    app.use(session({ secret: 'bla' }));
    

    Changed passportConfig to be down and it worked:

    app.use(cookieParser());
    app.use(session({ secret: 'bla' }));
    passportConfig(app);
    
    0 讨论(0)
  • 2020-12-13 05:06

    I encountered the same problem when I set up my own route handler from which I called passport.authenticate (). I forgot that passport.authenticate returns middleware that must be invoked, so just calling passport.authenticate isn't sufficient. Then I replaced

    router.post("/",
     function(req,res,next){
       passport.authenticate("local", function(err, user, info){
    
        // handle succes or failure
    
      }); 
    })
    

    with

    router.post("/",
     function(req,res,next){
       passport.authenticate("local", function(err, user, info){
    
        // handle succes or failure
    
      })(req,res,next); 
    })
    
    0 讨论(0)
提交回复
热议问题