#has anyone succesfully integrated TRPC with tanstack start WITH SSR?

4 messages · Page 1 of 1 (latest)

ebon nacelle
#

looking for some guidance on this.

how does trpc fit in with tanstack router? of course we store it in the router context...
but how do we handle creating a new query client for each request AND where does useTRPC fit in there?

still anchor
#

tRPC version 11 now integrates tightly with TanStack Query. Let's try it out on TanStack Start and find out how to query both inside and outside the React context.

Code: https://github.com/jherr/start-trpc/tree/main/start-trpc-pt-1

Part 1: What you're watching now
Part 2: https://youtu.be/uE4devDh2rU

This video was sponsored by Infinite Red: ...

▶ Play video
stone canopy
#

but this does not have auth part with ssr?

#
export const trpc = createTRPCOptionsProxy<AppRouter>({
    client: createTRPCClient({
        links: [
            httpBatchStreamLink({
                url: `${import.meta.env.VITE_BETTER_AUTH_URL}/api/trpc`,
                fetch: (url, options) => {
                    if (typeof window === "undefined") {
                        const headers = getHeaders();
                        return fetch(url, {
                            ...options,
                            headers: {
                                ...options?.headers,
                                ...headers,
                            },
                        });
                    }
                    return fetch(url, options);
                },
            }),
        ],
    }),
    queryClient: TanstackQuery.getContext().queryClient,
});