Add configuration options for SvelteKit Adapter handler resolve
function
#12356
scott181182
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
handler
to pass to SvelteKit'sresolve
function, liketransformPageChunk
,filterSerializedResponseHeaders
, andpreload
Non-Goals
No response
Background
I'm using Auth.js in my SvelteKit project, in which I use
load
functions to fetch data from my API so I can Server-Side Render (SSR) my views. The API client that I'm using (ts-rest) needs access to the "Content-Type" header on the API responses in order to parse the response body. For pre-rendering pages, this works wonderfully, but I'm now integrating with TanStack which requires the API queries to be available on the client-side (and therefore during hydration). This makes my API client send fetch requests during hydration on the client-side, but SvelteKit caches these responses so it doesn't actually need to send a network request when SvelteKit'sfetch
function takes over. Fantastic, we love to see SSR working.However, SvelteKit doesn't expose any of the headers on these cached requests by default. They even have a nice configuration option to allow some headers, like "Content-Type", to be passed through. Now I'm following the Auth.js documentation to setup my
hooks.server.ts
, but I can't configure it at all to pass those headers through that my API client needs to parse cached responses during client-side hydration.The workaround is fairly straightforward: mask the
handle
invocation and give it your ownresolve
function that does apply the wanted options:I think this is unnecessarily verbose compared to being able to specify this in the
SvelteKitAuth
function, especially if there were multiple places I want to use thehandle
function it returns.Proposal
I think
@auth/sveltekit
should add an additional field to theAuthConfig
interface, along the lines of:This can then be passed to the
resolve
invocation in theSvelteKitAuth
function:This passthrough option would allow developers more control over their server handlers as SvelteKit changes.
Beta Was this translation helpful? Give feedback.
All reactions