maddest
maddest12mo ago

trpc openapi does not work on app router

https://github.com/jlalmes/trpc-openapi Can i just know if trpc open api for next is also applicable for app router, the repo has example for pages router but not for app router, i tried to replicate that to app router but it is failing by something like this [get-computers is just an api endpoint] my issue: it is working in pages router but i recently added context to trpc in which i am using nextauth for getting session, latest next auth does not seem to work on pages router as i read through one issue that multiple people are facing this with nextauth but i wanted to know if i can sue approuter and not rely on pages router to use trpc-openapi-next route handler? code : app/api/[...trpc]/route.ts
import { NextApiRequest, NextApiResponse } from "next";
import { createOpenApiNextHandler } from "@turbocell/trpc/openApi";
import { appRouter } from "@turbocell/trpc";
import { createContext } from "@turbocell/trpc/server/context";

async function handler(req: NextApiRequest, res: NextApiResponse) {
const context = await createContext({ req, res });
return createOpenApiNextHandler({
router: appRouter,
createContext: () => context,
})(req, res);
}

export { handler as GET, handler as POST };
import { NextApiRequest, NextApiResponse } from "next";
import { createOpenApiNextHandler } from "@turbocell/trpc/openApi";
import { appRouter } from "@turbocell/trpc";
import { createContext } from "@turbocell/trpc/server/context";

async function handler(req: NextApiRequest, res: NextApiResponse) {
const context = await createContext({ req, res });
return createOpenApiNextHandler({
router: appRouter,
createContext: () => context,
})(req, res);
}

export { handler as GET, handler as POST };
GitHub
GitHub - jlalmes/trpc-openapi: OpenAPI support for tRPC 🧩
OpenAPI support for tRPC 🧩. Contribute to jlalmes/trpc-openapi development by creating an account on GitHub.
No description
1 Reply
maddest
maddestOP12mo ago
is createOpenApiNextHandler limited to pages router or am i doing doing something wrong in implementing that to app router?