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

前端 未结 14 1445
小鲜肉
小鲜肉 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 02:34

    This could also be an issue with your client's POST/GET calls. I had this exact same issue but it turned out that I had to give fetch (which is what I was using) the option credentials:'include' like so:

    fetch('/...', {
      method: 'POST',
      headers: myHeaders,
      credentials: 'include',
      body: ...
      ...})
    

    The reason is because fetch doesn't support passing down cookies, which is necessary in this case.

提交回复
热议问题