Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Deleting Cookies #5

Closed
britztopher opened this issue Apr 25, 2017 · 3 comments
Closed

Not Deleting Cookies #5

britztopher opened this issue Apr 25, 2017 · 3 comments

Comments

@britztopher
Copy link

britztopher commented Apr 25, 2017

I'm submitting a ... (check one with "x")

[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior
When calling cookies.removeAll or cookies.remove functions the cookies are not deleted and are still persisted in browser

Expected/desired behavior
I expect the cookies to be deleted

Reproduction of the problem
If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar.
This is in TS, so I cannot reproduce in plnkr. But I can share some code. I have 2 modules, an app.modules, which is my main module, and a core.module which holds all core app components and services. I included the CookieModule.forRoot() to the app module as directed in the usage as well as in my core module, where i have tried CookieModule.forChild() and forRoot() with no avail.

App Module

@NgModule({
  imports: [
    CoreModule,
    CookieModule.forRoot(),
    BrowserModule,
    AppRoutingModule,
    SharedModule,
    LoginModule
  ],

Core Module

@NgModule({
  imports: [
    HttpModule,
    CommonModule,
    FormsModule,
    CookieModule.forChild()
  ],

Then within my service in Core module I inject the service using my constructor and use the cookies service as follows:

constructor(private cookies: CookieService) {
  }

  public logout() {
    this.sessionStorage.clear();
    this.cookies.remove('auth.token');
    //cookie is still there with same value
    console.log('auth token cookie::', this.cookies.get('auth.token'));
    this.setLoggedIn(false);
  }

When i console.log the output i see the token after its supposed to be deleted.

In addition, Im using webpack 2 and am importing ngx-cookie in my vendor.browser.ts like so:

import 'ngx-cookie';

What is the expected behavior?
I expect the cookie auth.token to be removed.

Please tell us about your environment:

  • **ngx-cookie version:**0.0.0-development - as seen in package.json

  • Angular version: 4.1.0-beta.1

  • Browser: [ Chrome: 58.0.3029.81 (64-bit)]

@mbark
Copy link

mbark commented Jun 21, 2017

I ran into a similar problem but found that the reason was that when deleting the cookie you also need to take into consideration the domain and path cookie is set to (you can see those using i.e. the developer tools for Chrome).

In my case the application was running on local.domain.com but the cookie was set on .domain.com. Adding the domain made the cookie actually get deleted:

this.cookies.remove(name, { domain: '.domain.com' });

@celsomtrindade
Copy link
Contributor

The solution proposed by @mbark does solve the problem. Passing the same options used to put the cookies will delete. However, this only works to remove(), removeAll() still doesn't work, since it doesn't accept any params.

I think this can be solved easly by just adding an optional option param to the removeAll() function.

@salemdar
Copy link
Owner

salemdar commented Nov 1, 2017

Merged the PR. Thanks 👍

@salemdar salemdar closed this as completed Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants