Cookies not getting set
See original GitHub issueExpected Behavior
Cookie being set
Actual Behavior
No cookie being set
Steps to Reproduce the Problem
What i’m trying to do is to store a JWT token in a cookie using following code. ` setCookie(name: string, value: string, encrypt: boolean, days?: number) { let date = null; if (days) { date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); }
if(encrypt){
value = btoa(value);
}
this.cookie.set(name, value, date, "/", environment.domain, true);
}`
but the cookie is not getting created. I stept into the code of the plugin and no errors happen there.
Specifications
- Version: Angular 6
- Host: LocalHost and deployed version
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
7 Keys to the Mystery of a Missing Cookie - Medium
7 Keys to the Mystery of a Missing Cookie · 1. SameSite attribute Defaults to Lax · 2. withCredentials is not Set to...
Read more >Cookie not being set in browser - Stack Overflow
I can see it being returned in the response header set-cookie: xxxxxx but for whatever reason, the browser is not storing the cookie....
Read more >Response cookies not being set · Issue #386 · github/fetch
I'm trying to implement client login using fetch on react. I'm using passport for authentication. The reason I'm using fetch and not regular ......
Read more >Set-Cookie - HTTP - MDN Web Docs
The Set-Cookie HTTP response header is used to send a cookie from the server ... to the client the cookie is being set...
Read more >Laravel Sanctum - Cookies not being set - Laracasts
Laravel Sanctum - Cookies not being set. I have followed the instructions and set it all up https://laravel.com/docs/9.x/sanctum#how-it-works.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have done further testing and it looks like there is an inherent problem with how cookies are read back when used in conjunction with an Angular router. I don’t know how to resolve this other than by explicitly setting the path to “/”. It does not work otherwise with a different path as described in my stackoverflow post.
I have problem where cookie values are not persisted in IE or Edge. Still investigating what could be causing it…
UPDATE: I have found the cause of my issue. I was not setting the path when setting the cookie. In Chrome it was setting the root path and the page specific path where the cookie was set from (why both). In IE, it was doing only the latter. I am not sure what is the expected behavior when not specifying the path but it is strange the behavior is different from IE than other browsers.