question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cookies not getting set

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
phoudecommented, Jun 28, 2018

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.

3reactions
phoudecommented, Jun 26, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found