mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 20:19:33 +01:00
27 lines
611 B
TypeScript
27 lines
611 B
TypeScript
import * as trpc from '@trpc/client'
|
|
// @ts-expect-error: Resolved by Nuxt
|
|
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
|
|
import type { router } from '~/server/trpc'
|
|
|
|
declare type AppRouter = typeof router
|
|
|
|
export default defineNuxtPlugin(() => {
|
|
const config = useRuntimeConfig().public.trpc
|
|
const client = trpc.createTRPCClient<AppRouter>({
|
|
url: `${config.baseURL}${config.trpcURL}`,
|
|
headers: useRequestHeaders(),
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
client,
|
|
},
|
|
}
|
|
})
|
|
|
|
declare module '#app' {
|
|
interface NuxtApp {
|
|
$client: trpc.TRPCClient<AppRouter>
|
|
}
|
|
}
|