ngx-cookie-service: Delete not working

Expected Behavior

    this.cookieService.set('Test', 'Hello World');
    console.log(this.cookieService.getAll());
    this.cookieService.delete('Test');
    this.cookieService.delete('Test', '/');
    this.cookieService.delete('Test', '/', 'localhost');
    console.log(console.log(this.cookieService.getAll()));
{Test: "Hello World"}
{}

cookie is deleted

Actual Behavior

    this.cookieService.set('Test', 'Hello World');
    console.log(this.cookieService.getAll());
    this.cookieService.delete('Test');
    this.cookieService.delete('Test', '/');
    this.cookieService.delete('Test', '/', 'localhost');
    console.log(console.log(this.cookieService.getAll())); 
{Test: "Hello World"}
{Test: "Hello World"}

cookie is not deleted

Steps to Reproduce the Problem

Specifications

  • Version: 3.0.2
  • Browser: chrome

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 18 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Work around: instead of trying to delete the cookie, set it again with an expired date. That’s how delete is coded to work - it just gets applied to the wrong domain when in a subdomain.

set('panda_cookie', '', new Date('Thu, 01 Jan 1970 00:00:01 GMT'), '/', 'domain', true, 'None')

I have the delete method not working issue happening for me as well, running cookie-service 12.0.3 with Angular 12.1.3. Seems to be completely random, I can’t find a common denominator for steps to reproduce reliably.

3.0.3 fixed the issue described here

Hi @piaro , yes, try to set sameSite, because sameSite default = ‘None’, maybe different sameSite in your browser, f12 and check your sameSite.

I am still facing the issue with delete and deleteAll in my localhost. Sometimes Its working, sometimes not. Tried Many ways, but none worked for me.

Apparently, I have the same trouble with deleting. Using 3.1.3, because of having older angular version. Delete on localhost does work, but on further environments .delete() does not have any effect. Tried with no arguments and with full list of ones matching the list visible in browser dev tools.

for new version of ngx-cookie-service delete functionality should work. if it does not work for you - please provide a test spec for it.

The issue is still relevant for me with 3.0.4