ngx-cookie icon indicating copy to clipboard operation
ngx-cookie copied to clipboard

Cookie set on server cannot be read on server returns undefined.

Open Muzummil opened this issue 3 years ago • 4 comments

Description Cookies saved on angular SSR are returned as undefined while values are there in browser cookies. This is happening only on the HTTPS site with localhost everything is working as expected.

To Reproduce Steps to reproduce the behavior:

  1. Save cookies on the server-side and use them on the server-side also and you will get the undefined value.

Environment:

  • Angular version [11]
  • Angular Universal version [11]
  • ngx-cookie : ["^5.0.2"],
  • ngx-cookie-backend: ["^5.0.2"]

Muzummil avatar Oct 18 '21 14:10 Muzummil

Based on skimming the source code. Its because when you set a cookie on SSR you set it to the response object. When you read cookies the service reads from the request object.

bamma avatar Nov 03 '21 04:11 bamma

The issue I created #465 may be duplicate, although the issue I'm experiencing is also running SSR in dev on localhost. Its possible if the localhost run being processed was not using SSR, that the experience would work. This is why it could potentially be a duplicate issue.

Additionally the issue may have been tough to track down without knowing multiple cookies on a domain needed to be set.

nicholasconfer avatar May 12 '22 20:05 nicholasconfer

@Muzummil can you recheck with 6.0.1?

salemdar avatar Jun 30 '22 11:06 salemdar

@salemdar It seems as if 6.0.1 has fixed this issue.

selected-pixel-jameson avatar Feb 17 '23 10:02 selected-pixel-jameson