1

I am trying to set a cookie on the client side in my react web app.
I am using CRA deployed to Firebase.

Tried both js-cookie and react-cookie - in both cases I see that the set cookie code is running correctly.
When developing in localhost everything works perfectly - yet in production no cookie is ever being created.

Am I missing something?

amiregelz
  • 1,833
  • 7
  • 25
  • 46
  • Is your cookie named `__session`? Firebase infrastructure strips cookies named anything else at the networking layer meaning it never hits the backend. Try changing the cookie's name and test again. – samthecodingman Feb 13 '22 at 00:09
  • How do you know the cookie isn't set? Is it by checking it in JavaScript or do you use a browser extension? Check properties `httpOnly` which makes the cookie invisible to JS and `secure` which will make the browser not accept the cookie if it's set on an unsecure (http) connection. Also check that the domain of the cookie corresponds to your url. Check headers in the network tab in the development tools to check whether subsequent requests contain the cookie or not. – fast-reflexes Feb 13 '22 at 07:36
  • 1
    @fast-reflexes Weirdly enough, now it looks like everything's working. Didn't change anything. I was checking it by inspecting the Application tab in Chrome DevTools and refreshing the items there. Maybe there have been some bug preventing me from seeing it, idk. – amiregelz Feb 13 '22 at 18:20
  • Did you try production mode in localhost? does that work? – marzzy Feb 14 '22 at 06:47

1 Answers1

0

According to react-cookie docs setCookie(name, value, [options]) and removeCookie(name, [options]) accepts domain key in options object. Are you using your production url as a value of domain key ?

Guram Khasia
  • 114
  • 4