Skip to content

Links

The links exported by trpc-nuxt/client are convenience wrapper around the tRPC’s links that replaces regular fetch with $fetch from Nuxt, sets a default url (/api/trpc), and sets the default headers using useRequestHeaders.

plugins/trpc.ts
import { createTRPCNuxtClient, httpLink } from 'trpc-nuxt/client'
import type { AppRouter } from '~/server/trpc/routers'
const client = createTRPCNuxtClient<AppRouter>({
links: [
httpLink({
// Select headers to pass to `useRequestHeaders`.
// By default, `useRequestHeaders()` returns all headers.
pickHeaders: ['authorization']
}),
],
})