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.

Can't set multiple cookies with res.cookie

See original GitHub issue

Problem with res.cookie

I am trying to set multiple cookies with res.cookie. (Only the last one saved)

My code:

const cookieParser = require('@tinyhttp/cookie-parser').cookieParser;
const TinyApp = require('@tinyhttp/app').App;
const app = new TinyApp();

const parse = cookieParser(CookieSecret);
const cookieTime = 1000 * 60 * 60 * 24 * 3;

app.get("/SetInfo", async (req, res) => {
    if(req.query.cookies){
        await new Promise(next => parse(req, res, next));
        res.cookie("name", 1, { httpOnly: true, signed: true, maxAge: cookieTime });
        res.cookie("pass", 1, { httpOnly: true, signed: true, maxAge: cookieTime });

        console.log(req.signedCookies);
        // {pass: 1}
    }
    res.send('ok');
    res.end();
})

app.listen(8080);

I tried @tinyhttp/cookie-parser and cookie-parser, but the same results.

Versions

  • node: 12.19.0
  • @tinyhttp/app: 1.1.5
  • @tinyhttp/cookie-parser: 1.1.6

Does someone know what may be the problem?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
talentlessguycommented, Jan 12, 2021

Ok i think this is fixed, at least tests for multiple res.cookie calls pass.

to install:

pnpm i @tinyhttp/app@1.1.9

lmk if the issue still occurs or you need extra help about it

1reaction
ido-plutocommented, Jan 10, 2021

Greate, thanks for the help. BTW I adore this framework. The speed is Amazing! (~ ̄▽ ̄)~

Read more comments on GitHub >

github_iconTop Results From Across the Web

How set multiple cookies with res.cookie(key , value) on ...
You simply call cookie more than once without calling send in between them. Call send only after you've done all the cookies, ...
Read more >
Can't set multiple cookies with res.cookie · Issue #215 · tinyhttp ...
Problem with res.cookie I am trying to set multiple cookies with res.cookie. (Only the last one saved) My code: const cookieParser ...
Read more >
SameSite cookies - HTTP - MDN Web Docs
Cookies will be sent in all contexts, i.e. in responses to both first-party and cross-site requests. If SameSite=None is set, the cookie ......
Read more >
ExpressJS - Cookies - Tutorialspoint
ExpressJS - Cookies, Cookies are simple, small files/data that are sent to client with a server request and stored on the client side....
Read more >
Using cookies - Postman Learning Center
You can't override cookie headers directly in the Headers tab. Edit the cookie in the cookie manager, or delete the cookie and set...
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