Nodejs and PassportJs: Redirect middleware after passport.authenticate not being called if authentication fails

前端 未结 4 1087
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 11:53

I have no login page but rather I have a login form that appears on every page. I want to redirect user back to the same page they were on regardless of whether authenticati

4条回答
  •  隐瞒了意图╮
    2020-12-14 11:57

    I know this might still be a problem for some people like me who tried all the suggested options without any success.

    In my case, as it turned out, I was getting the error because my req.body object was always empty. I had my body parsing middleware set up correctly so it didn't make sense why this was happening.

    After more research I found out that the enctype I was using for my forms(multipart/form-data) isn't supported by body-parser - see their read me - after switching to a different middleware, multer, everything worked smoothly.

提交回复
热议问题