Headers
We can use the built-in useRequestHeaders to set outgoing request headers:
createTRPCNuxtClient has this feature by default.
plugins/client.ts
export default defineNuxtPlugin(() => { const headers = useRequestHeaders() const client = createTRPCProxyClient<AppRouter>({ links: [ httpBatchLink({ // headers need to be a function so it gets called dynamically // every HTTP request headers() { // You can add more custom headers here return headers } }), ], }) return { provide: { client, }, }})
server/trpc/context.ts
export function createContext (event: H3Event) { console.log('cookies', parseCookies(event)) return {}}