The cookie doesn't allow response on production environment
See original GitHub issueThe scenario is when the backend service based Koajs and Koa-session with the default configuration:
app.keys = [process.env.SESSION_SECRET];
const isProd = process.env.NODE_ENV === 'production' ? true : false;
const SESSION_CONFIG: any = {
key: 'koa:sess',
maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days
overwrite: true,
httpOnly: isProd,
signed: true,
rolling: true,
renew: false,
secure: isProd,
sameSite: 'None',
};
When the request calling to the endpoint and get an error code 500, it doesn’t respond as expected and set the cookie to the browser.
But when removing secure
and sameSite
, it’s working but the cookie doesn’t set to the browser.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
The cookie doesn't allow response on production environment
The cookie doesn't allow response on production environment. This issue has been tracked since 2020-12-28. The scenario is when the backend service based ......
Read more >Cookies are not being set in production - Stack Overflow
Most likely, The Right domain is not associated with the cookie being set so while setting the cookie, the browser silently rejects the...
Read more >7 Keys to the Mystery of a Missing Cookie - Medium
Check out the OPTIONS response header ACCESS-CONTROL-ALLOW-CREDENTIAL whether it is set to true . If the server doesn't allow credentials being ...
Read more >Response cookies not being set · Issue #386 · github/fetch
I'm trying to implement client login using fetch on react. I'm using passport for authentication. The reason I'm using fetch and not regular ......
Read more >Everything You Need to Know About Cookies for Web ...
Cookies with HttpOnly can only be accessed by the server, and not by the browser's Document.cookie API. This is perfect for things like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @dominicegginton , The solution above was helpful and we also can set
domain: 'api.domain.com'
in the configuration. Maybe this is also a session to learn.const SESSION_CONFIG = { key: 'koa:sess', maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days overwrite: true, httpOnly: isProd, signed: true, rolling: true, renew: false, secure: isProd, sameSite: 'None', domain: 'api.anotherdomain.com', }
Thanks for your help!Thanks all, I already fixed the issue.
I’ll re-format the answer of @phivh to make it more readable