|
Following this: https://svelte.dev/docs/kit/single-page-apps In my root I have export const ssr = false;The load function here is running my auth checks (api call to separate server) using I know that generally if I had a SvelteKit server, I would use export const load = async ({ parent }) => {
return parent()
} So I thought in SPA mode it would make sense to use Seems like Am I doing auth check correctly then in Note: I am getting some stale data on updating the session data. Can’t use Tanstack query in |
Replies: 3 comments 9 replies
|
What are you protecting here that your server can't? To avoid repetition you can customize your fetch function. |
|
I can directly relate to your position @arkmech.. spa's are an under valued pattern and a lot of things get lost in translation 😬 The whole reason this thread exists is that, in SPA mode, there isn't first‑class handle‑style hook on the client. Folks are ending up duplicating auth checks in every layout or load function, or wiring up ad‑hoc Now, if you want something that feels closer to the "global middleware" pattern (which is what I believe is being asked for here), svelte5‑router might be worth a look (I cranked this out for this very case). It gives you pre & post navigation hooks out of the box — meaning you can run your auth check before a route is allowed to resolve, trigger analytics, or other side‑effects beofre/after navigation. In practice, that means you define the guard once and every protected route respects it. It won’t replace SvelteKit’s core router, but for projects committed to I threw up a snazzy demo at https://demo.router.svelte.spa/protected which is basically: Feel free to ping me if ya have questions or concerns! |
I’ve created an issue for this in #15151 please feel free to continue the discussion there if a hook for the fetch we use in sveltekit on the client would be a sufficient solution.