-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Cookie path not settable using $cookies service #1786
Comments
$cookieStore service had no way to set cookie attributes (such as expires). The api for $cookieStore.put and $cookieStore.remove now has a third argument- options,which allows setting cookie attributes, or deleting cookies under a specific path. - to change the path and/or expiration date of a cookie, you can pass an options object as the third argument to cookies(name,value). the options object can override Path and Expires when adding a value. You can pass either path, expires,none or both. - the path option is checked to be a string and be partial to window.location otherwise, the default path is used. (warning is logged) - the expires option is checked to be a Date and in the future, otherwise no expiration is set. (warning is logged) - you can now delete a cookie on a specific path by calling cookie(name,undefined,{path:x}) The $cookie service remains unchanged since supporting cookie attributes would mean serious backward comptability issues. Foundations were put in place to make supporting $cookie easier. GENERIC TEST CHANGE: To support checking cookie path, all unit-tests now run on path "/karma/tests" Documentation was updated for both $cookie and $cookieStore with examples. closes angular#1786, angular#1320 BREAKING CHANGE: As part of the change, deleting a cookie now deletes cookies set in multiple paths (and duplicate cookies if exists). Previously only cookies set in the / path were deleted. Since it is not intutive, if this change breaks someones code, it is probably as an accidental side-effect. It is reasonable to assume that most people actually wanted to delete the cookie even if it wasn't set in the same path (since they can see it). So while this is a breaking change, it fixes bad behaviour. If needed, you can delete the cookie in a specific path using $cookieStore.
👍 |
1 similar comment
👍 |
Did this ever get accepted? |
👍 |
3 similar comments
👍 |
👍 |
👍 |
👍 |
We need this feature. +1 |
+1 |
+1 |
6 similar comments
+1 |
+1 |
+1 |
👍 |
+1 |
+1 |
In the meantime you can use https://github.com/ivpusic/angular-cookie. example : |
+1 |
+1 |
+1 |
To anyone looking to keep all cookie paths the same everywhere, adding |
Thank you @ajspera. Can confirm your solution works. |
Did the documentation get updated? The proposed solution seems like a workaround. It's been a while since I had to use base href on a website. The last time I did I'm pretty sure it was a legacy situation on the server side and we couldn't have used this workaround without piles of money and time to rebuild the backend. Isn't the bug/feature request a better solution overall than the one accepted to close this issue? |
+1 |
4 similar comments
+1 |
👍 |
+1 |
👍 |
+1 I have the opposite problem, I have a site at abc.xyz and I need cookies to be restricted to abc.xyz/a or abc.xyz/b etc so I need to be able to explicitly set the path of the cookies one level down from the base. |
👍 |
👍 |
3 similar comments
👍 |
👍 |
+1 |
The `put`, `putObject` and `remove` methods now take an options parameter where you can provide additional options for the cookie value, such as `expires`, `path`, `domain` and `secure`. Closes angular#8324 Closes angular#3988 Closes angular#1786 Closes angular#950
The `put`, `putObject` and `remove` methods now take an options parameter where you can provide additional options for the cookie value, such as `expires`, `path`, `domain` and `secure`. Closes angular#8324 Closes angular#3988 Closes angular#1786 Closes angular#950
When using the $cookies service, there is no easy way to set the path of the cookie to match every path on the domain.
On line 3137 of angular.1.0.2.js the path of all cookies created is set as self.baseHref()
When trying to write the same cookie from different paths this results in additional cookies being created due to the different path.
With no facility implemented to pass in a path, the path needs to be hard coded in order to be changed.
The text was updated successfully, but these errors were encountered: