From 5333bfd87a1ba4416236604a1e3b68c379a19195 Mon Sep 17 00:00:00 2001 From: Valknar XXX Date: Wed, 29 Oct 2025 05:36:16 +0100 Subject: [PATCH] fix: use native fetch for getVideoBySlug to fix authenticated SSR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Convert getVideoBySlug from Directus SDK to native fetch API - Fixes serialization errors when authenticated users view video pages - Remove unused readUsers import from @directus/sdk - Directus SDK returns non-serializable objects with circular refs - Native fetch returns plain JSON that works with SvelteKit SSR 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/frontend/src/lib/services.ts | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/frontend/src/lib/services.ts b/packages/frontend/src/lib/services.ts index 57d7477..b307050 100644 --- a/packages/frontend/src/lib/services.ts +++ b/packages/frontend/src/lib/services.ts @@ -5,7 +5,6 @@ import { updateMe, readMe, registerUserVerify, - readUsers, passwordRequest, passwordReset, customEndpoint, @@ -243,27 +242,28 @@ export async function getVideoBySlug( return loggedApiCall( "getVideoBySlug", async () => { - const directus = getDirectusInstance(fetch); - return directus - .request( - readItems("sexy_videos", { - fields: [ - "*", - { - models: [ - "*", - { - directus_users_id: ["*"], - }, - ], - }, - "movie.*", - ], - filter: { slug }, - }), - ) - .then((videos) => { - if (videos.length === 0) { + const fetchFn = fetch || globalThis.fetch; + return fetchFn( + `${directusApiUrl}/items/sexy_videos?${new URLSearchParams({ + filter: JSON.stringify({ slug: { _eq: slug } }), + fields: JSON.stringify([ + "*", + { + models: [ + "*", + { + directus_users_id: ["*"], + }, + ], + }, + "movie.*", + ]), + })}`, + ) + .then((res) => res.json()) + .then((response) => { + const videos = response.data; + if (!videos || videos.length === 0) { throw new Error("Video not found"); } // Handle models array - filter out null/undefined and map to user objects