GhostBob
GhostBob4mo ago

Svelte: server side: call queries?

How can I call convex functions: queries, mutations, etc... from +page.server.ts from the load: PageServerLoad function? According to the docs, I need to add to +layout.svelte the following code: setupConvex(PUBLIC_CONVEX_URL); which is done. But as soon as I add const sessionJson = useQuery(api.auth.user.validateSession, { sessionId: sessionCookie }); into my load function I get the error: Svelte error: lifecycle_outside_component getContext(...) can only be used during component initialisation
No description
4 Replies
GhostBob
GhostBobOP4mo ago
No description
ballingt
ballingt4mo ago
@GhostBob something like this? https://github.com/get-convex/convex-svelte/blob/main/src/routes/%2Bpage.server.ts useQuery is for components, not loaders
GhostBob
GhostBobOP4mo ago
@ballingt thank you, it's helped!
iScream
iScream4mo ago
And to make it "global" use a server hook...
No description

Did you find this page helpful?