req.session undefined and req.session.user_id not working

后端 未结 1 1663
予麋鹿
予麋鹿 2021-01-06 20:52

I am using Express and node for the session management with https. I want to create a session using express so that authentication and the session is made before the redirec

相关标签:
1条回答
  • 2021-01-06 21:15

    The session middleware checks if an incoming request matches the cookie path; if not, it doesn't bother continuing (and req.session won't even be created). In your situation, your cookie path is set to /public/, which doesn't match the request path /login.

    I think you'd want to configure the session middleware cookie to use / as a path:

    app.use(express.session({
      cookie: {
        path    : '/',
        httpOnly: false,
        maxAge  : 24*60*60*1000
      },
      secret: '1234567890QWERT'
    }));
    
    0 讨论(0)
提交回复
热议问题