Cookies set on development, but not on production #5850
Replies: 3 comments
-
Are you running the NextJS app locally, and backend elsewhere? If that is so, your cookie probably got restricted to the backend's ip/domain |
Beta Was this translation helpful? Give feedback.
-
in your login function, try setting httpOnly to true, your cookie might be deemed insecure as clientside JS can access it, and might be ignored res |
Beta Was this translation helpful? Give feedback.
-
I agree with @danillo7789, here's the same thing, res
.status(200)
.cookie("accessToken-Myapp", accessToken, {
secure: true, // Ensure you are using HTTPS in production
httpOnly: true, // This ensures the cookie is not accessible via JavaScript
sameSite: "none"
})
.end(); Also, I would take a look at this res.cookie(name, value [, options]) in Express 4x API Reference. |
Beta Was this translation helpful? Give feedback.
-
2 Docker containers:
I tested it on localhost with Docker Compose: Everything working fine (both Postman and the browser successfully store the token as a cookie to use on subsequent requests.).
I deployed it to Google Cloud Run (one service for each container). Everything working fine except that now only requests made through Postman are storing the token as a cookie.
The browser (the Next.JS app) no longer does the same, even though the request returns a successful response there is no token in the browser cookies.
I did some research, found a few similar problems, and the solutions usually involve setting up some CORS configurations, so I updated my code by adding these configurations, but the issue remains.
I am currently trying it like this:
Server-side:
Client-side:
Beta Was this translation helpful? Give feedback.
All reactions