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
handlerto pass to SvelteKit'sresolvefunction, liketransformPageChunk,filterSerializedResponseHeaders, andpreloadNon-Goals
No response
Background
I'm using Auth.js in my SvelteKit project, in which I use
loadfunctions 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'sfetchfunction 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
handleinvocation and give it your ownresolvefunction that does apply the wanted options:I think this is unnecessarily verbose compared to being able to specify this in the
SvelteKitAuthfunction, especially if there were multiple places I want to use thehandlefunction it returns.Proposal
I think
@auth/sveltekitshould add an additional field to theAuthConfiginterface, along the lines of:This can then be passed to the
resolveinvocation in theSvelteKitAuthfunction:This passthrough option would allow developers more control over their server handlers as SvelteKit changes.
Beta Was this translation helpful? Give feedback.
All reactions