[SvelteKit] Settings initial data for session from a loader function #6280
Unanswered
HugeLetters
asked this question in
Q&A
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.
-
I'm using tanstack-query v4, svelte-query & trpc-svelte-query. In order to make prefetching work I have to do this I have to do this
(This is recommended by trpc-svelte-query docs - I've tried to put hydrateFromServer in the
+layout.ts
so I could then providequeryClient
through loader and have access to it anywhere but it doesn't work for whatever reason :| )And so I have
to check for session - but I also wanna have an option to refetch it/invalidate it when needed so I guess I would also need a tRPC procedure which can provide me with a fresh session data which I will then get through trpc-query. But I don't wanna to fetch session the second time on mount - I already have that data from layout loader. So I would like to put it in queryClient cache - but I don't have access to it due to the reasons in the first 2 code snippets. I also wouldn't wanna use initialData for that cause that's rather cumbersome to do that for each query.
So the only solution I found so far is to have a
layout.svelte
like thisThis works but feels anti-idiomatic since I'm doing the side-effect in my initial render. Is that ok? Is there a better solution?
I also would to redirect wherever my query returns a null session if it got invalidated for whatever reason/
To reiterate what I wanna do
trpc.auth.getSession.query()
wherever I want and this data will be available immediately due to step 2.I can link a repo if that helps - however it will require a Google OAuth set-up.
Beta Was this translation helpful? Give feedback.
All reactions