aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web/server/api/client.ts
blob: 130f4f87a760023c8ccd2d34a72b2bd5ac2bc60a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { appRouter } from "./routers/_app";
import { getServerAuthSession } from "@/server/auth";
import { Context, createCallerFactory } from "./trpc";
import { db } from "@hoarder/db";

export const createContext = async (database?: typeof db): Promise<Context> => {
  const session = await getServerAuthSession();
  return {
    user: session?.user ?? null,
    db: database ?? db,
  };
};

const createCaller = createCallerFactory(appRouter);

export const api = createCaller(createContext);