Express-session Secure Cookies not working

后端 未结 7 782
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 00:16

When not using secure cookie true setting, my app user login works fine. When I enable secure cookies, the login appears to go through fine, but it seems the cookie is not s

7条回答
  •  难免孤独
    2021-01-18 01:02

    The combination of settings that worked for me:

    • Inside the nginx server configuration, add proxy_set_header X-Forwarded-Proto $scheme;
    • Inside the express-session configuration:

      server.use(
        session({
          proxy: true, // NODE_ENV === 'production'
          cookie: {
            secure: true, // NODE_ENV === 'production'
          },
          // everything else
        })
      );
      

提交回复
热议问题