Hizen
Hizen
TTCTheo's Typesafe Cult
Created by Hizen on 12/31/2023 in #questions
Trouble setting tRPC with NextJs App Router
I figured it out after 2 hours lol, when we setup the route handler we need to return the fetchRequestHandler directly, not wrap it arond the curly bracket. The correct implementation is this:
const handler = ( req: NextRequest ) =>
fetchRequestHandler( {
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: () => ( {} )
} );
const handler = ( req: NextRequest ) =>
fetchRequestHandler( {
endpoint: '/api/trpc',
req,
router: appRouter,
createContext: () => ( {} )
} );
2 replies