BCJTI / ng2-cookies

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

cookieService.delete not working in a custom service #57

Closed resting closed 7 years ago

resting commented 7 years ago

Trying to do this.cookieService.delete('authToken'); in a login.service but it doesn't delete. deleteAll() doesn't work either.

But injecting cookieService in component works. Any idea?

resting commented 7 years ago

I did more tests and found that actually it doesn't delete the cookie in a subscribe method. Any idea why?

this.myAccountService.changePassword(this.password, this.newpassword)
.subscribe(
  d => {
    this.cookieService.delete('authToken'); // <-- not deleting
  },
  e => this.onError(e)
)

It doesn't delete either when I do a redirect with router.navigate.

resting commented 7 years ago

I found the issue. I didn't set the path when setting or deleting the cookie. After setting the path to /, it is deleting fine now.