What problem does it solve?
Middleware composition in tRPC can be verbose and error-prone; this Skill reduces boilerplate and prevents common pitfalls by showing how to authenticate, authorize, log, time, trace, and safely extend request context for server procedures.
Core Features & Use Cases
- Auth & Context Narrowing: patterns for creating authedProcedure and adminProcedure that guarantee non-nullable user context downstream.
- Observability: logging and timing middleware patterns for request duration measurement and integration points for OTEL tracing.
- Reusable Plugins & Composition: how to build reusable middleware with .concat() and extend middleware chains with .unstable_pipe() for ordered context enrichment.
- Safety Guidance: explicit warnings about calling and returning opts.next(), and correctly extending ctx with proper typing to avoid runtime or security issues.
Quick Start
Use the middlewares skill to create an authedProcedure that validates ctx.user, throws an UNAUTHORIZED TRPCError when missing, and returns opts.next with a narrowed ctx.user so downstream procedures see a non-nullable user.