🇵🇸 Prince Toast
tRPC3y ago
1 reply
🇵🇸 Prince Toast

I can't mutate or query in SvelteKit

Environment: Node 20 with Yarn
I'm not getting any specific errors but I don't get the "mutate" or "query" methods with trpc client in SvelteKit. Here is the situation:
My API is written in Fastify. I'm using the Fastify adapter for tRPC. On the client, I get autocompletion for the routers (like user.createAccount or post.getAll) but I don't get the ability to mutate or query data.
// api.ts file in lib folder
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../backend/src/router';

export const api = createTRPCProxyClient<AppRouter>({
    links: [
        httpBatchLink({
            url: 'http://localhost:5173/api',
            // You can pass any HTTP headers you wish here
            async headers() {
                return {
                    authorization: (localStorage.getItem('token')
                        ? localStorage.getItem('token')
                        : '') as string
                };
            }
        })
    ]
});
Was this page helpful?