Hey, I'm having trouble with saving a cookie in production on my app and I need help. I'm deploying the frontend on Vercel, and backend express server on Railway.
res.cookie('token', token, {
httpOnly: true,
maxAge: 86400000,
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
secure: process.env.NODE_ENV === 'production',
path: '/',
});
This is the cookie that I send to the client upon successfully logging in. The client receives the response with 200 status, displays a notification that login was successfull, the cookie shows up in application/cookies and in network request (without any errors, as if it was applied), but then a redirect to '/' happens and it attempts to read the cookie and its no longer there. Basically the cookie is received and saved but just for a split second.
This works perfectly fine in local development on localhost, the cookie is saved and persists on all pages, refreshes, redirect etc.