Miquel
Miquel

Reputation: 8969

$cookies.remove not working for http://localhost/path/#!/

A node.js server working on http://localhost:3000 is setting a cookie for root path (path: '/').

There are two angular apps:

Both apps can see all cookies for http://localhost:3000 and path: '/'.

When using $cookies.remove(cookieName) from http://localhost:3000/#! app it works fine.

When using $cookies.remove(cookieName) from http://localhost:3000/admin/#! it doesn't remove the cookie.

Is there any way to remove cookies from sub-path without having to modify the path in server? (I preffer not to do it as both apps share some routes that use cookies).

Upvotes: 2

Views: 3392

Answers (1)

Mike
Mike

Reputation: 3940

The problem is that the ngCookies module assume that all of the cookies you edit will only be attributed to the path that you are currently on and doesn't allow you edit other cookies unless you specifically configure it to do so. If you want to edit a cookie on path / from /admin You need to add an object in the objects param with a path index pointing to the path set in the cookie you wish to remove.

In your case:

$cookies.remove(cookieName, {path: '/'});

Upvotes: 8

Related Questions