0

I am creating a cookie by using react babel but I am facing a problem. When I create a cookie the cookie created in the browser but when I click on the URL to authenticate then the cookies remove from the browser, and when I create it again, the two cookies with an old one and a new one is created in the browser. When I delete a cookie and refresh the page the two cookies again created in the browser. I don't understand how is this possible? I am using this code to create and delete a cookie-

              cookies.remove("WebTimeClock", {
                path: "/labor-settings",
                domain: "localhost",
              });

and for create a cookie I am using this-

                  cookies.set("WebTimeClock", currentUniqueID, {
                    expires: new Date(dateTime),
                  });

I am using "react-cookie" for this.

1 Answer 1

1

You can set multiple cookies of the same name if you set them against different paths. In your first example, you define the path, but in the second, you do not. Not setting a path will use the existing URL path. If I do this on stack overflow, you can see from dev tools there are now two cookies:

Two foo cookies on different paths

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.