Skip to content

Commit 3b43388

Browse files
committed
feat: add handleFetch to manage cookie forwarding for localhost SSR requests
1 parent e7005db commit 3b43388

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/hooks.server.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { config, ready } from "$lib/server/config";
2-
import type { Handle, HandleServerError, ServerInit } from "@sveltejs/kit";
2+
import type { Handle, HandleServerError, ServerInit, HandleFetch } from "@sveltejs/kit";
33
import { collections } from "$lib/server/database";
44
import { base } from "$app/paths";
55
import { authenticateRequest, refreshSessionCookie, requiresUser } from "$lib/server/auth";
@@ -262,3 +262,17 @@ export const handle: Handle = async ({ event, resolve }) => {
262262
}
263263
return response;
264264
};
265+
266+
export const handleFetch: HandleFetch = async ({ event, request, fetch }) => {
267+
if (isHostLocalhost(new URL(request.url).hostname)) {
268+
const cookieHeader = event.request.headers.get("cookie");
269+
if (cookieHeader) {
270+
const headers = new Headers(request.headers);
271+
headers.set("cookie", cookieHeader);
272+
273+
return fetch(new Request(request, { headers }));
274+
}
275+
}
276+
277+
return fetch(request);
278+
};

0 commit comments

Comments
 (0)