How to use jquery/ajax data for passportjs

前端 未结 3 441
梦谈多话
梦谈多话 2020-12-06 03:29

If I send a login request using the form fields action=\"/login\", method=\"post\", it works just fine. Similar to the code available here or here.

But

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 04:04

    Perhaps this is a better place than buried in the comments. I experienced something similar months ago, and answered my own question here:

    Passport authenticate callback is not passed req and res

    essentially I was able to get it to work having the post handled with the signature: req, res, next and inside of that handler you call the passport.authenticate with the desired strategy. The passport.authenticate shouldn't be (or at least in my case wouldn't function as) the handler for the route

    server.post(route, function(req, res, next){
    
        passport.authenticate('local', function(err, user) {
    
        })
    
    })
    

    I was never able to get the passReqToCallback option to work.

提交回复
热议问题