ScottHamper / Cookies

JavaScript Client-Side Cookie Manipulation Library
The Unlicense
1.77k stars 169 forks source link

Quickly clear all cookies under a domain #52

Open seowyanyi opened 9 years ago

seowyanyi commented 9 years ago

Is there a way to clear all cookies under a domain, for example when a user logs out?

ScottHamper commented 9 years ago

Hey @seowyanyi ,

Currently there's no way to do this without clearing each cookie individually.

This is actually a tricky feature to add. The native JS cookies API (document.cookie) will only expose a list of keys and values for set cookies - options like path, domain, and secure are not included. So while a cookie may have been set with a specific domain, there's no way to tell when examining the cookie later on.

The only possible way to implement a feature like this, would be to use a "shotgun" approach. Where, for each cookie, attempt to expire it with the passed in domain value. If the cookie was set under that domain, it would be successfully expired, otherwise nothing would happen.

This is definitely something to consider adding to the library.

p-decoraid commented 8 years ago

https://github.com/p/delete-all-cookies does this (as well as clearing cookies for parent domains).