meal_planner/plugins/client.ts
2024-12-15 01:18:09 +01:00

30 lines
671 B
TypeScript

import { createTRPCNuxtClient, httpBatchLink } from "trpc-nuxt/client";
import type { AppRouter } from "~/server/trpc/routers";
export default defineNuxtPlugin(() => {
const headers = useRequestHeaders();
/**
* createTRPCNuxtClient adds a `useQuery` composable
* built on top of `useAsyncData`.
*/
const client = createTRPCNuxtClient<AppRouter>({
links: [
httpBatchLink({
url: "/api/trpc",
headers() {
// add custom headers here
return {
Authorization: "Bearer token",
...headers,
};
},
}),
],
});
return {
provide: {
client,
},
};
});