Reputation: 317
Hi everybody,
after hours of googling and trying every approach I could find I haven't found a solution to my problem.
I am trying to save a JWT Token in an HttpOnly cookie but although my server sends the cookie correctly it doesn't get set in the browser.
I have CORS enabled on the server-side, the cookie being sent is not Secure
has the Path '/'
and has set SameSite=none
. The domain is set to localhost
because that's where my frontend is running and HttpOnly=true
.
The cookie is received correctly and is visible in Chrome as token=eyJ...hcP; Max-Age=31104000; Domain=localhost; Path=/; Expires=Thu, 05 Aug 2021 12:22:35 GMT; HttpOnly, SameSite=None
I'm guessing the problem is that the frontend is running on localhost:3000 and the backend on localhost:4000.
I would appreciate any help, thank you!
Upvotes: 2
Views: 1105
Reputation: 2531
I'm guessing the problem is that the frontend is running on localhost:3000 and the backend on localhost:4000.
This is the answer. localhost:4000
and localhost:3000
are not the same domain when regarding cookies.
The most common solution is to use webpack-dev-server
. This dev-server will be responsible for two things.
So you will need to implement this as a part of your frontend development environment.
Upvotes: 1