BCJTI / ng2-cookies

Simple library to deal with cookies in Angular2
64 stars 31 forks source link

Duplicate Cookies #60

Closed NikolaJankovic closed 6 years ago

NikolaJankovic commented 6 years ago

I'm having an issue where certain routes of my application have multiple cookies by the same name. This only happens on certain routes, when you navigate away from them the duplicate cookie (with a different value in my case) disappears.

I've looked through the source code and set() just applies the cookie using document.cookie which I don't believe checks for duplicates, however when I attempted to apply duplicates intentionally calling set() twice with different values, only the latest value persisted.

I can't figure out if this is a common issue (no other issues mention it) and if delete() needs to be called prior to updating the cookie value. I'm also not sure why it only occurs on a single route when the a path argument isn't passed when calling set().

NikolaJankovic commented 6 years ago

The issue was caused by not specifying the path which caused identical cookies to be set on different routes. Passing a path argument of '/' - which I assumed was the default behaviour - seems to have solved the issue.

Bigous commented 6 years ago

Tks @NikolaJankovic ! The default depends on the browser...