feat: createContext

This commit is contained in:
Justin Lin committed 2025-04-16 15:36:12 +08:00
1 parent 6326b84a60
commit 529869671c
3 files changed
+18 -8

No files matched your search

+14 -5
View File
@@ -1,9 +1,18 @@
import { initTRPC } from '@trpc/server'
/**
* Initialization of tRPC backend
* Should be done only once per backend!
*/
const t = initTRPC.create()
import { CreateNextContextOptions } from '@trpc/server/adapters/next'
export const createContext = async (opts: CreateNextContextOptions) => {
const { session, user, ip } = opts.req
return {
session,
user,
ip,
}
}
export type AppContext = Awaited<ReturnType<typeof createContext>>
const t = initTRPC.context<AppContext>().create()
/**
* Export reusable router and procedure helpers
* that can be used throughout the router