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.

Fetch in load function not sending cookie when in production

See original GitHub issue

Describe the bug

  1. No issue in setting a cookie. Cookie is set and present in browser.
  2. Cookie is being sent by the same code when it is running in localhost .
  3. Problem : In production, fetch in load function isn’t sending cookie, but browser fetch is able to send cookie.

Reproduction

I created a svelte-kit repo running on https://expense.satyam.life/ . When you run it it just shows you a button set cookie. When you click the button cookie is set using an endpoint and you are redirected to a page displaying cookie sent by load_fetch and browser_fetch.

The backend fastify repo](https://github.com/mishrasatyam/fastify_send_read_cookie) is running on https://expenseapi.satyam.life/ . It has two routes (one for creating cookie, other for sending back cookie received in request header).

Again, I am not having any issue when both servers are running on localhost. I am using seperate EC2 ubuntu 20.04 machines for deployment.

Logs

No response

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (1) x64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    Memory: 223.23 MB / 978.57 MB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.8.0 - ~/.local/share/pnpm/node
    npm: 7.21.0 - ~/.local/share/pnpm/npm
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.44 => 1.0.0-next.44
    @sveltejs/kit: next => 1.0.0-next.162
    svelte: ^3.34.0 => 3.42.4

Severity

serious, but I can work around it

Additional Information

Work around is calling an endpoint from load fetch and using headers in endpoint. But this is a serious issue and hope it gets fixed soon. Thanks.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bomgarcommented, Aug 25, 2022

I don’t get it. So a cookie on .example.com is not forwarded when my sveltekit server is on webapp.example.com and my API is on api.example.com.

This is a bit annoying. How would I handle this in the load function then?

Edit: found this discussion: #4750

0reactions
mishrasatyamcommented, Sep 6, 2021

Thanks I got it. I changed the backend url to api.expense.satyam.life and it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extension fetch function not sending cookies
Assuming the fetch call is made from the background script, you'll need to query the cookies and insert those in the http header....
Read more >
Fetching data from the server - Learn web development | MDN
This article shows how to start working with Fetch to fetch data from the server.
Read more >
5.x API - Express.js
The function determines the file to serve by combining req.url with the provided root directory. When a file is not found, instead of...
Read more >
setcookie - Manual - PHP
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before...
Read more >
Serving - web.dev
Using the service worker's fetch event, you can intercept network requests ... page visits after a site's first load to be rendered without...
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