4 months ago
## Problem
I'm trying to set cookies from my Railway backend and redirect to my localhost frontend during development, but cookies are not being saved in the browser.
## Environment
- **Backend**: NestJS + Fastify on Railway (HTTPS)
- **Frontend**: Next.js on localhost:8000 (HTTP)
- **Flow**: Email verification → Railway backend sets cookie → Redirect to localhost
## Current Setup
### Backend (Railway)
```typescript
// Cookie options
{
path: '/',
httpOnly: true,
sameSite: 'none',
secure: true
}
// CORS config
{
origin: 'http://localhost:8000',
credentials: true
}
// After email verification
reply.setCookie('accessToken', token, cookieOptions);
return reply.status(302).redirect('http://localhost:8000/callback/signup');
```
### Issue
When the backend redirects to localhost, the `Set-Cookie` header is sent but the cookie doesn't appear in the browser.
I understand this is a cross-origin issue (Railway domain → localhost domain), but I'm wondering:
1. Is there a Railway-specific configuration I'm missing?
2. Should I use `trust proxy` settings?
3. What's the recommended approach for development with Railway backend + local frontend?
## What I've Tried
- ✅ `sameSite: 'none'` + `secure: true`
- ✅ CORS `credentials: true`
- ✅ Frontend using `credentials: 'include'`
- ❌ Still no cookies in browser after redirect
Any guidance would be appreciated!3 Replies
4 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
4 months ago
If I’m understanding the question correctly, cookies are always scoped to the domain that sets them, so a cookie issued by yourapp.up.railway.app won’t be stored or sent when the browser is redirected to a different origin like localhost:8000.
weston
If I’m understanding the question correctly, cookies are always scoped to the domain that sets them, so a cookie issued by yourapp.up.railway.app won’t be stored or sent when the browser is redirected to a different origin like localhost:8000.
4 months ago
Then what should I do…?
My frontend is running on localhost with Next.js, and I want to test login and signup with the backend deployed on Railway.
How can I make the cookies be saved in the browser during these tests?