Server-Side Cookies

I’m trying to make an app in Sveltekit using Cloudflare Pages, however I need to access user cookies on the server-side to protect authenticated pages. For some reason though, I cannot access the “cookie” header coming from the request in my Sveltekit hooks function, and presumably in other server-side rendering functions.

Is this a limitation of Cloudflare Pages or am I doing something wrong?

I am attempting to grab the cookie like so:

export const handle: Handle = async ({ event, resolve }) => {
     const cookies: string = event.request.headers.get('cookie');
[...]
}

request.headers.get('cookie') should absolutely work. Are you certain the cookie is being sent? Can you retrieve any other headers?

Yes, I looked in my Network requests and it shows the cookie header being passed to Cloudflare Pages.

Essentially I’m trying to get this cookie to pass it to my API for authentication checks. However, the cookie string is just blank. I tried passing cookies using fetch and putting them into query parameters, but they show up as blank values.

I have a similar issue. Checking the cookie on hooks.ts, it works in localhost, it is certainly sending the cookie with the page request when in Cloudflare, but is like it’s always undefined.

BTW, how do you debug the Svelte hooks function in Cloudflare pages?

Thanks.