0

I'm learning sveltekit but struggling to get the value of a cookie from a response after use fetch to get the response. Here is my code which in the +page.svelte and +page.js in src/roots code:

// +page.js
let url = "api/getacookie"

/** @type {import('./$types').PageLoad} */
export const load = async ({ fetch }) => {

    let response = await fetch(url) 
    console.log("see if response has set-cookie header :", response.headers)
 
    let aboutcookie = await response.json()
    // reponse has the cookie in the headers. How to get the cookie value?

    return { aboutcookie }
}

How do I get -extract the cookie from the headers - the cookie from the response?

Marco
  • 1,051
  • 19
  • 41
  • What is stopping you? You are already logging `response.headers`, that is where the cookie would be stored if there is any. – H.B. Jul 18 '23 at 00:47
  • H.B Thank you for helping. The question was how do I get the cookie from the response so I can pass it on to the vite server and set it in a hook or something. – Marco Jul 18 '23 at 12:16
  • I still fail to what is stopping you, it's a standard [`Headers` object](https://developer.mozilla.org/en-US/docs/Web/API/Headers), the API is not that complicated, and there are various libraries for parsing cookies if you do not want to do it yourself. – H.B. Jul 18 '23 at 12:20

0 Answers0