Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
Sending cookie from Express to React
Post Flair (click to view more posts with a particular flair)
Post Body

My app's back-end is an Express API, and I run a React SPA (vite) on the front-end.

I'm implementing the "Sign in with Google" functionality. During development, when testing on localhost, I could:

- Click on the Sign In button (it's an anchor tag, not a Fetch request)
- This targets by back-end auth route (/auth/google)
- I use Passport's Google strategy which then targets the callback route (if login successful)
- In the "/auth/google/callback" route, I get the user, create a signed JWT token, which I then send back to the front-end as a cookie that I set (res.cookie, then res.redirect to front-end).
- Back on the React front-end, on the redirect it gets the cookie, and I can then fetch whatever back-end protected route I like, using Fetch with "credentials: include".

This whole process has been working fine while testing, I could log in, log out, access my routes, etc...

I've now hosted my app (frontend on Render, backend on Railway), and modified the Google account settings (which were previously set for localhost:xxxx, and now my hosting url).

Now on the hosted site, when I click on "Sign in with Google", I can see from my back-end logs that I am successfully signed in, but for some reason the cookie I set isn't sent to the front-end. I don't get any errors, it's just that the front-end doesn't get the cookie, so it's like I'm never signed in.

And I don't know why it was working on localhost, and suddenly stopped working in "production". All the ressources I've read about the issue on google, simply say to set the fetch request with "credentials: include" option, but in my case it's not a fetch request from the front-end.

Any clues on how to get around that?

Author
Account Strength
90%
Account Age
3 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,182
Link Karma
62
Comment Karma
8,120
Profile updated: 4 days ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago