Cookies between localhost and google app engine (custom google domain) not persistant

Viewed 97

I'm on this for a long time and I can't find a solution. So my problem is:

I have a react front-end and a nodejs/express backend working well installed on local (the app is supposed to get 3 cookies from the back to run correctly) So I deployed my backend on google app engine (with custom domain).

The front can log in the app and get theses cookies, but theses cookies are not persistant. They disappear if I try to reload the page or click on a link (get the account for exemple).

Code for the front-end can be find here: front-end Code for the back-end can be found here: back-end

The app is working like: You try to log => if successful you get 3 cookies including one with a JWT. After the front is supposed to look into theses cookies to get the UI working right.

Thanks for your help.

1 Answers

OK so after weeks of research and testing I resolve it (on netlify).

Like I said the backend was on google app engine with a customised domaine and the frontend on localhost (or netlify for online test).

So I had to set a customised domaine to netlify too and get both on the same domain. They just have 2 different subdomain.

I had to explicitly set the domain to my cookie (using js-cookie). So my cookies (on the backend) looks like:

cookie("groupomania", true, {
    maxAge: 7200000,
    httpOnly: false,
    sameSite: "None",
    secure: true,
    domain: "myDomain.com"
    
  })

My fetches options requests had theses options:

method: "POST",
  headers: { "Content-Type": "application/json" },
  credentials: "include",
  crossDomain: true,

So if this explanation can help someone I'm happy with that. Have a nice day!

Related