const createInnerTRPCContext = (opts: CreateContextOptions) => { console.log("DB FROM INNER CONTEXT", opts.db); return { db: opts.db, request: opts.request, };};
import { createNextApiHandler } from "@trpc/server/adapters/next";import { withIronSessionApiRoute } from "iron-session/next";import { env } from "@/env.mjs";import { appRouter } from "@/server/api/root";import { createTRPCContext } from "@/server/api/trpc";import { NextApiRequest, NextApiResponse } from "next";import { sessionOptions } from "@/utils/session";const handler = (req: NextApiRequest, res: NextApiResponse) => { return createNextApiHandler({ router: appRouter, createContext: createTRPCContext, onError: env.NODE_ENV === "development" ? ({ path, error }) => { console.error( `❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`, ); } : undefined, })(req, res);};export default withIronSessionApiRoute(handler, sessionOptions);
- wait compiling /api/trpc/[trpc] (client and server)...- event compiled successfully in 605 ms (142 modules)
"next": "13.4.12",
"@trpc/client": "^10.38.3", "@trpc/next": "^10.38.3", "@trpc/react-query": "^10.38.3",
const { data: news } = api.news.getAllNews.useQuery();