React + Next : Not sending cookies from server-side to backend React + Next : Not sending cookies from server-side to backend kubernetes kubernetes

React + Next : Not sending cookies from server-side to backend


I'm (also?) doing an online course around this and ran into this same issue. The issue being that some calls to getInitialProps() don't always include the application context for some reason. Unfortunately, I don't have a direct answer for why that's failing. Regarding the missing cookies, you may be requiring that your cookies are only sent over secure https connections? For example, here's what I've got in my project:

app.use(  cookieSession({    name: "teekeet.com session",    signed: false, // Disable cookie encryption to better support different service platforms (java, ruby, nodejs etc)    secure: process.env.NODE_ENV !== "test", // Cookies should only be used over HTTPs    maxAge: 1 * 10 * 60 * 1000, // 10mins  }));

In any case, assuming you're running version 9.3+ of NextJS then you should move to the newer APIs that provide explicit Server Side rendering hooks. Specifically the getServerSideProps() API.The NextJS docs provide a good explanation on how to use the new features. Check out their guide here. Also, feel free to poke around my project in github as a reference.