ntraithi(Min)
ntraithi(Min)
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
thanks again man
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
done!
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
Gonna close this with the solution 1. check cors config
app.use(
cors({
origin: 'your url link';
credentials: true,
})
);
app.use(
cors({
origin: 'your url link';
credentials: true,
})
);
2.check your session, cookie to have these 3 set.
app.use(
session({
...
cookie: {
secure: true,
sameSite: 'none',
httpOnly: true,
},
})
);
app.use(
session({
...
cookie: {
secure: true,
sameSite: 'none',
httpOnly: true,
},
})
);
I also set domain to client url at first, didn't think it's would cause problem. Unfortunately when I removed it, it worked. 3. trust proxy app.set('trust proxy', 1); 4. On your client side, when sending request include your credentials
const res = await axios.post<FormData>(
'https://your-server-production.up.railway.app/api/users/signin',
{
email: formData?.email,
password: formData?.password,
},
{ withCredentials: true }
);
const res = await axios.post<FormData>(
'https://your-server-production.up.railway.app/api/users/signin',
{
email: formData?.email,
password: formData?.password,
},
{ withCredentials: true }
);
5. If you use see set-cookie in the response header, but no cookies in the next request header. Check your Browser cookie setting and allow 3rd party cookie.
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
Hey @Brody , just wanna let you know it's working now. Thank you so much. As a self-taught dev, it means the world to me and I truly appreciate your help. God bless you man 🙌
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
thank you so much for your advice. I learned from an online course and they dont really teach you how these infrastructure stuff works. Please correct me if Im wrong. 1.When we use CORS, we’re telling server to handle request and response from specific origin only 2. When we deploy to Railway, our server is running behind a proxy server which is like a middleman now. 3. The server doesn’t know that there’s a proxy, and knows only the origin stated in CORS so it refuses to send set cookie to proxy and also to the client. If we modify the server code to let them know that there’s a proxy (by setting server to trust proxy) , then it should be able to send cookie through proxy and to client. So does the client has to send their request to proxy address now instead of https://workout-timer-server-production.up.railway.app/ ??
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
Hi Brody thanks for checking in. Could you provide more detail about how this work? do i just set app.enable('trust proxy',true or client ip.address)? or is there any other thing I should be checking on?
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
Project ID:4e42c618-d84d-4687-9344-b9aa95f39c6c
18 replies
RRailway
Created by ntraithi(Min) on 7/28/2023 in #✋|help
Set-Cookie isn't sent with res header on production
N/A
18 replies