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

reactCookie.remove not functioning. #16

Closed
jcdavison opened this issue Feb 2, 2016 · 28 comments
Closed

reactCookie.remove not functioning. #16

jcdavison opened this issue Feb 2, 2016 · 28 comments

Comments

@jcdavison
Copy link

I can't believe this is actually a problem with the library, but is there some condition in my application that could be causing behavior like what I'm observing in this console screenshot?

https://www.dropbox.com/s/805pyfznabpyr54/Screenshot%202016-02-02%2012.57.18.png?dl=0

Other pages in the application appear to be working as expected.

@eXon
Copy link
Collaborator

eXon commented Feb 2, 2016

If you do a page refresh, is the cookie removed?

@jcdavison
Copy link
Author

The one detail that I notice is that the cookie will clear properly with non dynamic route

/labs then in helper module Cookie.remove(token) works
but
/labs/:id Cookie.remove(token) does not work.

Any thought on what is causing this?

For context, I've got a react app using relay in conjunction with a rails backend.

@eXon
Copy link
Collaborator

eXon commented Feb 2, 2016

This is probably a path problem with your cookie. Make sure to do:

cookie.save('token', value, { path: '/' }); 
// ...
cookie.remove('token', { path: '/' });

Browsers are bitches about that.

@skrshisode
Copy link

Same occurred to me a day ago. Passing { path: '/' } solves the problem.

Thanks a lot!

@zachfejes
Copy link

@eXon that was SUPER helpful! Thanks :)

@masterial
Copy link

Does not work. >:(

@eXon
Copy link
Collaborator

eXon commented Aug 12, 2018

@destinatis can you be more precise about your issue? Please open a new one with steps to reproduce.

@yaskovdev
Copy link

To me it started removing only after I specified both path and domain:

cookies.remove('token', { domain: COOKIE_DOMAIN, path: COOKIE_PATH })

@thxallgrace
Copy link

This is probably a path problem with your cookie. Make sure to do:

cookie.save('token', value, { path: '/' }); 
// ...
cookie.remove('token', { path: '/' });

Browsers are bitches about that.

@eXon It works in my case! THANKS

@kimuyjoong
Copy link

To me it started removing only after I specified both path and domain:

cookies.remove('token', { domain: COOKIE_DOMAIN, path: COOKIE_PATH })

Super help for me! thanks !

@besil
Copy link

besil commented Jun 4, 2019

I'm experiencing the issue. Didn't help adding domain or path

new Cookies().remove('token', {path: "/", domain: "localhost"});

I'm using Firefox Developer Edition in private mode.

With chrome, it's working fine, even without the domain option.

I suppose @eXon's comment "Browsers are bitches about that" is more true than I believed

@remjx
Copy link

remjx commented Jun 6, 2019

I'm having a similar problem except I can't even get it to remove in Chrome... @besil this issue is closed so you might want to open a new issue.

@MatthieuStadelmann
Copy link

I'm having a similar problem too. Did you find a solution @markjackson02 @besil ?

@besil
Copy link

besil commented Jun 18, 2019

Found out FF extensions did cause interference.
After disabiling all of them, cookie deletion started working.

In Chrome everything worked fine (I have no extensions there)

@MatthieuStadelmann
Copy link

Thanks for answering. Well, I think I have the same problem on Chrome where I have extensions but on Firefox it works fine.

@remjx
Copy link

remjx commented Jun 18, 2019

@MatthieuStadelmann My workaround is to use Express's res.clearCookie() which clears the client cookie when it receives the response

@MatthieuStadelmann
Copy link

Thanks @markjackson02

However, I don't use express in my React application. I need to be able to remove the cookies when the user logs out.

@remjx
Copy link

remjx commented Jun 18, 2019

@MatthieuStadelmann Can you use LocalStorage instead of cookies? In any case, I think this is deserving of a new issue. This one is closed so probably none of the devs of this package will see this thread.

@MatthieuStadelmann
Copy link

@markjackson02 No, for security purpose I can't. But you're right, I'll open a new thread if I can't find a solution :-)

@kennethbrent
Copy link

I had the same issue and could not figure out the problem - setting domain and path was not working. I don't know why but once i changed my function to an arrow function it works as expected.
signOut(){ Cookies.remove('cookies_name') } to signOut = () => { Cookies.remove('cookies_name') }

@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?

@inthelamp
Copy link

RemoveCookie function removed the cookie, but I had to refresh a signout component which called the function and solve an infinite loop problem out of the component because of the refreshing.

@yvzkr
Copy link

yvzkr commented Sep 28, 2021

This is probably a path problem with your cookie. Make sure to do:

cookie.save('token', value, { path: '/' }); 
// ...
cookie.remove('token', { path: '/' });

Browsers are bitches about that.

you are KING
Senin heykelini dikmeye beton yetmez.

@6thpath
Copy link

6thpath commented Dec 22, 2021

This is probably a path problem with your cookie. Make sure to do:

cookie.save('token', value, { path: '/' }); 
// ...
cookie.remove('token', { path: '/' });

Browsers are bitches about that.

This works, ty

@RutvikStackDev
Copy link

This is probably a path problem with your cookie. Make sure to do:

cookie.save('token', value, { path: '/' }); 
// ...
cookie.remove('token', { path: '/' });

Browsers are bitches about that.

This solution has a flaw. After logged out if you refresh the page then it will login you back. At-least happened to me several times.

Please others also check if this is a case or not.

@egalindoEH
Copy link

This happened to me in latest version because I deleted setCookie in const [cookie, removeCookie] = useCookies([...]);

So removeCookie was being used as setCookie, just add it again: const [cookie, setCookie, removeCookie] = useCookies([...]);

@raibove
Copy link

raibove commented Dec 8, 2022

This happened to me in latest version because I deleted setCookie in const [cookie, removeCookie] = useCookies([...]);

So removeCookie was being used as setCookie, just add it again: const [cookie, setCookie, removeCookie] = useCookies([...]);

Thank you, this worked for me

@Nilinofficial
Copy link

I did the same but the cookie is removing only after clicking it twice on the first click it removes and adds cookie back automatically even if i add setCookie

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