#Cookie is not being saved in production

1 messages · Page 1 of 1 (latest)

ocean barn
#

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.

stiff bronzeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)