using react-cookie I set a cookie with my access token like the following:
import { Cookies } from "react-cookie";
const cookies = new Cookies();
cookies.set(
cookieName,
token,
{
domain: ".mydomainhere.com",
path: "/"
}
);
this cookie is set only once when signing in.
everything works fine (just one cookie with the correct info set) until I refresh the page on a not empty path like on www.mydomainhere.com/project/ABC123
(refreshing on www.mydomainhere.com/
works fine). At this point another cookie with the same domain and name shows up and path equal to /project
with an out of date token – it’s the one before the latest token. The other cookie (path /
) has the correct token, but since the browser uses the cookie with the longest path, I get an expired token error.
The cookie removal code is set as:
cookies.remove(cookieName, {
path: "/",
domain: ".mydomainhere.com"
});
I saw several other questions similar to that, but none matched my issue here.
I expected to always have only 1 cookie since I set its path as /
and react-cookie docs clearly says to use / as the path if you want your cookie to be accessible on all pages. I tried in multiple paths and they all bring the same issue, only changing the path of the duplicated cookie