Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie expiration trace problem in Chrome and Safari #648

Open
LazzyLizzard opened this issue Sep 4, 2024 · 0 comments
Open

Cookie expiration trace problem in Chrome and Safari #648

LazzyLizzard opened this issue Sep 4, 2024 · 0 comments

Comments

@LazzyLizzard
Copy link

I have a problem tracing cookie expiration in Google Chrome and Safari browsers - but everything works fine in Firefox. My goal is when a cookie expires I must show a modal.

What I'm doing:

  1. setting a test cookie with 15 seconds lifespan. This operation is successful.
 const [cookies, setCookie, removeCookie] = useCookies([COOKIE_NAME]);

 useEffect(() => {
  console.log('cookies', cookies);
  setCookieInfo(cookies[COOKIE_NAME] || 'NO');
}, [cookies]);

// some code skipped

 {COOKIE_NAME}: {cookieInfo}

<button
  onClick={() => {
    const date = new Date(Date.now() + 1000 * 15);
    setCookie(COOKIE_NAME, `TILL ${date.toUTCString()}`, {
       expires: date,
       path: '/',
    });
  }}
>
  1. In parent component I'm checking if cookie expires
const [cookies, setCookie, removeCookie, updateCookies] = useCookies([
        COOKIE_NAME,
    ]);

    useEffect(() => {
        const interval = window.setInterval(() => {
            const date = new Date();
            updateCookies();
            console.log('tick', date.toUTCString());
        }, 1000);

        return () => {
            console.log('CDU');
            window.clearInterval(interval);
        };
    }, [updateCookies]);

Expected: as soon as cookie is set, I see cookieInfo. As it's expired, I see NO instead of cookie info.
Actual: even if a cookie is expired, cookie information is still being displayed.
Environment: React 18, react-cookies - 7.2.0, Chrome 128.0.6613.86

Here's a repo with minimal code - https://github.com/LazzyLizzard/cookie-check. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant