feat(WEB-127): add trpc to handle requests both serverside and clientside
This commit is contained in:
27
server/context.ts
Normal file
27
server/context.ts
Normal 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>
|
||||
Reference in New Issue
Block a user