javascriptangularsessioncookiesngx-cookie-service

ngx-cookie gets deleted when link is opened in new tab in Angular Application


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


Solution

  • 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
    );