Express sends Set-Cookie but the browser never stores the cookie
Set-Cookie header present in the response but the cookie is missing in DevTools Application tabShort answer
res.cookie only writes a Set-Cookie header. The browser decides whether to keep it. It drops the cookie when Secure is set but the page is plain HTTP, when a cross-origin fetch has no credentials, when SameSite=None lacks Secure, or when Domain does not fit the host. Check the response headers first.
Fix it fast
1Find out which cause you have
Look at the raw response. If Set-Cookie is not there, your code never ran or headers were not applied. If it is there, a browser rule rejected it, so work through the causes.
curl -i http://localhost:3000/login2Match what you see, then jump to its fix
- 1
Works on localhost, fails on the deployed site that sits behind nginx or a load balancersecure: true on plain HTTP, or behind a TLS proxy that Express does not trustFix - 2
The front end runs on another origin, for example localhost:5173 calling localhost:3000A cross-origin fetch does not send or accept credentialsFix - 3
The cookie is needed for a cross-site request (an embedded or separately hosted front end)SameSite=None without SecureFix - 4
The cookie is rejected, or stored but not sent on other routesDomain or path does not fit the host that sets the cookieFix
- 1
What does the error look like?
Set-Cookie header present in the response but the cookie is missing in DevTools Application tabreq.cookies is empty on the next request
Cause 1 of 4
secure: true on plain HTTP, or behind a TLS proxy that Express does not trust
1Check
Secure cookies are sent only over HTTPS, and insecure http: pages cannot set them (localhost is an exception). Behind a proxy that ends TLS, Express sees plain HTTP unless trust proxy is set, so express-session refuses to set a secure cookie.
curl -i https://example.com/login | grep -i set-cookie2Fix
Tell Express to trust the proxy so it reads X-Forwarded-Proto, and make sure the proxy sends that header.
app.set('trust proxy', 1);3Verify
The Set-Cookie header now appears on the HTTPS response and the cookie is stored.
curl -i https://example.com/login | grep -i set-cookieConfirmed by github.com
Cause 2 of 4
A cross-origin fetch does not send or accept credentials
1Check
For CORS requests, browsers ignore Set-Cookie unless the request includes credentials. The server must answer with Access-Control-Allow-Credentials true and an explicit origin, not the * wildcard.
curl -i -H 'Origin: http://localhost:5173' http://localhost:3000/login | grep -i access-control2Fix
Set credentials include on the client, and allow that exact origin with credentials on the server.
// client
fetch('http://localhost:3000/login', { method: 'POST', credentials: 'include' });
// server (cors package)
app.use(cors({ origin: 'http://localhost:5173', credentials: true }));3Verify
The cookie appears in DevTools Application tab after the call.
curl -i -H 'Origin: http://localhost:5173' http://localhost:3000/login | grep -i access-control-allowConfirmed by developer.mozilla.org
Cause 3 of 4
SameSite=None without Secure
1Check
SameSite=None sends the cookie on cross-site requests, and the Secure attribute must also be set with it. With Lax, cross-site fetch requests do not carry the cookie.
curl -i http://localhost:3000/login | grep -i set-cookie2Fix
Set both attributes, and serve both sites over HTTPS.
res.cookie('sid', token, { httpOnly: true, secure: true, sameSite: 'none' });3Verify
Set-Cookie shows SameSite=None; Secure.
curl -i https://api.example.com/login | grep -i set-cookieConfirmed by developer.mozilla.org
Cause 4 of 4
Domain or path does not fit the host that sets the cookie
1Check
Domain must be the setting host or a parent domain, never a public suffix, and a leading dot is ignored. Path decides which URLs receive the cookie; res.cookie defaults to '/'.
curl -i https://api.example.com/login | grep -i set-cookie2Fix
Remove Domain to get a host-only cookie, or set a parent domain you control.
res.cookie('sid', token, { domain: 'example.com', path: '/', secure: true });3Verify
The cookie shows in DevTools under the expected domain.
curl -i https://api.example.com/login | grep -i set-cookieConfirmed by expressjs.com
How do I stop it coming back?
- Test cookies on the real HTTPS domain, not only on localhost.
- Keep one cookie options object so secure, sameSite, domain and path stay the same on set and clear.
- Set trust proxy once, with the exact number of proxy hops.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fixBack end
Browser blocks a stylesheet or script: MIME type mismatch with nosniff
The Network tab shows the asset URL answered with Content-Type text/html
With X-Content-Type-Options: nosniff the browser accepts a stylesheet only as text/css and a script only as a JavaScript type.
3 causes, each with a fix