passport's req.isAuthenticated always returning false, even when I hardcode done(null, true)

前端 未结 14 1394
小鲜肉
小鲜肉 2020-11-29 02:06

I\'m trying to get my Passport local strategy working.

I\'ve got this middleware set up:

passport.use(new LocalStrategy(function(username, password,         


        
14条回答
  •  抹茶落季
    2020-11-29 02:16

    I had the same issue by forgetting to add

    request.login()
    

    on

    app.post('/login', 
        function(request, response, next) {
            console.log(request.session)
            passport.authenticate('login', 
            function(err, user, info) {
                if(!user){ response.send(info.message);}
                else{
    
                    request.login(user, function(error) {
                        if (error) return next(error);
                        console.log("Request Login supossedly successful.");
                        return response.send('Login successful');
                    });
                    //response.send('Login successful');
                }
    
            })(request, response, next);
        }
    );
    

    Hopefully that might help for others that ended up here same reason as I did.

提交回复
热议问题