feat(WEB-127): add trpc to handle requests both serverside and clientside

This commit is contained in:
Simon Emanuelsson
2024-03-20 16:39:11 +01:00
parent 2087ac6c91
commit ec4da5798b
31 changed files with 422 additions and 40 deletions

27
server/context.ts Normal file
View File

@@ -0,0 +1,27 @@
import { auth } from "@/auth"
type CreateContextOptions = {
auth: typeof auth
}
/** Use this helper for:
* - testing, where we dont have to Mock Next.js' req/res
* - trpc's `createSSGHelpers` where we don't have req/res
**/
export function createContextInner(opts: CreateContextOptions) {
return {
auth: opts.auth,
}
}
/**
* This is the actual context you'll use in your router
* @link https://trpc.io/docs/context
**/
export function createContext() {
return createContextInner({
auth,
})
}
export type Context = ReturnType<typeof createContext>