Backend Boilerplates typescript Advanced

tRPC Router with Zod Input

Type-safe tRPC router procedure with Zod validation and context-based auth check.

typescript
import { z } from "zod";
import { router, publicProcedure, protectedProcedure } from "./trpc";

export const moduleRouter = router({
  list: publicProcedure
    .input(z.object({ category: z.string().optional(), page: z.number().default(1) }))
    .query(async ({ input, ctx }) => {
      return ctx.db.module.findMany({
        where: { category: input.category, isPublished: true },
        skip: (input.page - 1) * 20,
        take: 20,
      });
    }),
});

Prerequisites

  • trpc >= 10
  • zod
  • prisma

Pro Tips

  • → Combine with React Query for automatic cache invalidation.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
typescript
Level
Advanced
Read time
5 min
Published
Aug 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.