Files
Homarr/packages/api/src/server.ts
Meier Lukas fba767bde3 fix: cache is not exportet from react (#417)
* fix: cache is not exportet from react

* fix: format issue

* fix: type issue
2024-05-01 21:17:28 +02:00

22 lines
597 B
TypeScript

import { cache } from "react";
import { headers } from "next/headers";
import { createCaller, createTRPCContext } from "@homarr/api";
import { auth } from "@homarr/auth/next";
/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(async () => {
const heads = new Headers(headers());
heads.set("x-trpc-source", "rsc");
return createTRPCContext({
session: await auth(),
headers: heads,
});
});
export const api = createCaller(createContext);