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.

add a virtual cookie store

See original GitHub issue

Is your feature request related to a problem? Please describe.

Let’s say there are two mocked routes which look like this:

rest.get('https://example.org/set-cookie', (_, res, ctx) => {
    return res(ctx.cookie('key', 'value'));
}),
rest.get('https://example.org/require-cookie', (req, res, ctx) => {
    if (req.cookies.key === 'value') {
        return res(ctx.status(204));
    }

    return res(ctx.status(400));
}),

When invoking those routes with two chained request …

fetch('https://example.org/set-cookie').then(() => fetch('https://example.org/require-cookie'))

… the second request will get a 400 response since there is no cookie header send with the request.

Describe the solution you’d like

As far as I understand, this currently doesn’t work since the cookie is set by using document.cookie. This means that the cookie will always be associated with the domain of the current document which is not necessarily the domain the response came from. There seems to be no way to change this behavior.

I would therefore like to propose adding a virtual cookie store. It would keep track of the cookies set by calling ctx.cookie() and it would automatically set the appropriate header to each mocked request to the same domain.

Describe alternatives you’ve considered

As mentioned above I think there is no alternative right now since setting cookies via JavaScript is restricted for good reasons.

Additional context

I’m happy to start a PR for this if we conclude that this is something useful.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
chrisguttandincommented, Oct 27, 2020

What about adding an option to the start() function?

We could also warn users in case they turned of the virtual cookie store but attempt to store a cross-origin cookie via ctx.cookie().

1reaction
chrisguttandincommented, Nov 22, 2020

Thanks @kettanaito for creating the package. I created a new PR which uses that package. #469

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selling with Digital Cookie - Girl Scouts
The Digital Cookie platform lets consumers buy online—and gives girls more ways to participate, more ways to learn, and more ways to find...
Read more >
My Digital Cookie Platform
Ready to get started? ... You'll need a Digital Cookie platform login to set up and use the Digital Cookie mobile app. ......
Read more >
Solved This assignment is to create a virtual cookie | Chegg.com
This assignment is to create a virtual cookie shop, using python3. You are the store owner, you have an inventory of at least...
Read more >
Virtual Cookie Decorating: Cookie Tales | Virtual Events
Make your virtual office sweet with Cookie Tales, our fully-hosted no-bake cookie decorating virtual team building event.
Read more >
How to Host a Virtual Cookie Swap - Vlogmas Day 17 - YouTube
We can't have in person cookie swaps, but how about some ideas for a virtual one?? Here are my favourite baking essentials: 1....
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