● Zion Boggan
repos/Stepping App/apps/web/src/lib/trpc/server.ts
zionboggan.com ↗
18 lines · typescript
History for this file →
1
import { cookies } from "next/headers";
2
import { appRouter, validateSession, SESSION_COOKIE } from "@stepping/api";
3
import { getDb } from "@stepping/db";
4
import { DEV_USER_ID } from "@stepping/config";
5
 
6
export function serverCaller() {
7
  return appRouter.createCaller({
8
    db: getDb(),
9
    user: { id: DEV_USER_ID, role: "member" },
10
  });
11
}
12
 
13
export async function sessionCaller() {
14
  const db = getDb();
15
  const token = (await cookies()).get(SESSION_COOKIE)?.value ?? null;
16
  const user = await validateSession(db, token);
17
  return { caller: appRouter.createCaller({ db, user }), user };
18
}