createContext: () => createTRPCContext(req),
interface AuthContext {
auth: SignedInAuthObject | SignedOutAuthObject
}
const createInnerTRPCContext = async ({ auth }: AuthContext) => {
return {
auth,
}
}
export const createTRPCContext = async (req: NextRequest) => {
return await createInnerTRPCContext({ auth: getAuth(req) })
}
export type Context = trpc.inferAsyncReturnType<typeof createTRPCContext>
export const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
},
}
},
})
export const createTRPCRouter = t.router
createContext: () => createTRPCContext(req),
interface AuthContext {
auth: SignedInAuthObject | SignedOutAuthObject
}
const createInnerTRPCContext = async ({ auth }: AuthContext) => {
return {
auth,
}
}
export const createTRPCContext = async (req: NextRequest) => {
return await createInnerTRPCContext({ auth: getAuth(req) })
}
export type Context = trpc.inferAsyncReturnType<typeof createTRPCContext>
export const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
},
}
},
})
export const createTRPCRouter = t.router