1

I have used a PC to serve the website via LAN connection and use the IPv4 address instead of localhost for hosting the website on LAN.

I'm using the npm package http-server for serving the dist compiled angular application.

I'm using ngx-cookie-service for manipulating cookies in the angular application. However, the cookies get deleted when I open a page via router.navigate(). Also, the cookies don't always get deleted as well.

So I'm kinda confused as to what is happening with the cookies. What can be the reason?

P.S. I have not implemented session in the backend though.

Angular version : 10+ ngx-cookie-service: 11.0.2 browser: chrome 86

Pavan Jadda
  • 4,306
  • 9
  • 47
  • 79
Srinath Kamath
  • 542
  • 1
  • 6
  • 17

1 Answers1

2

Edit: There are many people facing the same problem as you are: https://github.com/stevermeister/ngx-cookie-service/issues/86

Some people suggested to fill out all the parameters of the SET method:

this.cookieService.set(
 cookieName,
 cookieValue,
 expirationDate,
 '/',
 someData,
 true, // secure flag
 'None' // sameSite property
); 
Marco Nascimento
  • 832
  • 8
  • 15
  • Let me clarify, I'm using ngx-cookie-service but the cookies get auto-deleted when I'm using on xampp but not on any shared hosting. Why is this so? – Srinath Kamath Dec 29 '20 at 07:24
  • 1
    What's the version of your ngx-cookie-service ? There are many people facing the same problem as you are: https://github.com/stevermeister/ngx-cookie-service/issues/86 Some suggested to fill all the parameterers of the SET method: this._cookieService.set( cookieName, cookieValue, expirationDate, '/', someData, true, <- secure flag 'None' <- sameSite property ); Have you tried this ? – Marco Nascimento Dec 30 '20 at 13:46
  • I'm using ``` "ngx-cookie-service": "^11.0.2"```. But I think the problem was the ```path``` where the cookie was set. I defined the path as you mentioned & it worked. Does lazy loading effect the cookie creation? – Srinath Kamath Dec 31 '20 at 05:13
  • Great! I'm gonna edit my answer then. Lazy loading routes should be able to access the cookies normally since cookies belong to the domain. – Marco Nascimento Jan 02 '21 at 14:07