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.

Hi, When calling in BROWSER http://localhost:3000/membre/identification/setcookie, cookie is set correctly. But when this api url is called by http request from my angular application (http://localhost:4200/home), cookie is not set. I don’t undersand why.

IdentificationController.ts:

...
@Get("/setcookie")
    setcookie(@Session() session, @Req() request: Request, @Res() response: Response)
    {
        session.membre = {}
        session.membre.id = 'OK';		
        session['membre'] = 'AZERTY';
        return session;
    }
// return  {"cookie":{"path":"/","_expires":null,"originalMaxAge":null,"httpOnly":true,"domain":"localhost","sameSite"
:false,"secure":false},"membre":"AZERTY"}

    
    @Get("/getcookie")
    getcookie(@Session() session, @Req() request: Request, @Res() response: Response)
    {		
        return {'session': session};
    }
// return {"session":{"cookie":{"path":"/","_expires":null,"originalMaxAge":null,"httpOnly":true,"domain":"localhost"
,"sameSite":false,"secure":false}}}
...

app.

expressApp.use(session({
        secret: 'cookie_secret',        
        resave: true,
        saveUninitialized: true,
        cookie: {
            //domain: 'localhost',
            sameSite: false,
            path: '/', 
            httpOnly: true, 
            secure: false, 
            maxAge: null
        }
    })); // use session middleware

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Aug 3, 2017

Web browsers do not allow that to happen for security reasons. For example, if you try to set a cookie on google.com from your site, when you then go to google.com that cookie is not set, because the web browser just ignored it for security reasons. We can only work within the limitations web browsers impose on cookies.

0reactions
ghostcommented, Aug 3, 2017

I suppose i should use proxy servers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

php - Why are my cookies not setting? - Stack Overflow
The problem comes from the fact that setcookie() doesn't set the cookies immediately, it sends the headers so the browser sets the cookies....
Read more >
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 >
Set-Cookie - HTTP - MDN Web Docs
Controls whether or not a cookie is sent with cross-site requests, providing some protection against cross-site request forgery attacks (CSRF).
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 >
Error: "State cookie not set or expired. Maybe you took too ...
Solution. Ensure that cookies are enabled in your browser. Cookies are required by certain connectors for users to authenticate with their API. After...
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