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

useCookie doesn't support options on remove #1518

Open
JoeDuncko opened this issue Sep 18, 2020 · 5 comments · May be fixed by #1524
Open

useCookie doesn't support options on remove #1518

JoeDuncko opened this issue Sep 18, 2020 · 5 comments · May be fixed by #1524

Comments

@JoeDuncko
Copy link

What is the current behavior?

useCookie currently doesn't support options on remove. That means that you can't remove any scoped cookies. See https://stackoverflow.com/questions/54861709/cookies-removeabc-not-working-in-reactjs/55593030 and bendotcodes/cookies#16.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

    const [cookie, setCookie, deleteCookie] = useCookie("cookie");

    setCookie(accessToken, {
            domain: document.domain.match(/[^.]*\.[^.]*$/)?.[0],
        });

    // This doesn't work because it doesn't pass the scope
    deleteCookie();

    // This is what needs to work, but since deleteCookie doesn't support `options`, it won't work
    deleteCookie({
            domain: document.domain.match(/[^.]*\.[^.]*$/)?.[0],
        });

What is the expected behavior?

A little about versions:

  • OS: macOS 10.15.6
  • Browser (vendor and version): Chrome 85.0.4183.102
  • React: 16.13.1
  • react-use: 15.3.4
  • Did this worked in the previous package version? No
JoeDuncko added a commit to JoeDuncko/react-use that referenced this issue Sep 18, 2020
@JoeDuncko JoeDuncko linked a pull request Sep 20, 2020 that will close this issue
13 tasks
@Boby
Copy link

Boby commented May 27, 2021

for me I used removeCookie('yourcookiename', { domain: '', path: '/' }); and it clears out but I had to refresh, anyway we can get the cookie domain?

@JoeDuncko
Copy link
Author

for me I used removeCookie('yourcookiename', { domain: '', path: '/' }); and it clears out but I had to refresh, anyway we can get the cookie domain?

No, there is no way to get the cookie domain. It's a security function, as the dev should know the domain of the cookie they are manipulating.

@JoeDuncko
Copy link
Author

Fixed in react-hookz/web in react-hookz/web#117

@wildfrontend
Copy link

wildfrontend commented Dec 20, 2021

so , why not to merge this pull request ?

@JoeDuncko
Copy link
Author

so , why not to merge this pull request ?

Unfortunately, react-use is no longer supported, so this PR probably won't ever make it in. See this issue by the last active react-use maintainer.

He's since moved moved on to react-hookz/web.

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

Successfully merging a pull request may close this issue.

3 participants