How to get a cookie in +page.js from a fetch reponse?

184 views Asked by At

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?

0

There are 0 answers