middlewares

Creates and composes tRPC middleware for Node.js TypeScript servers.

2|Updated Apr 11, 2026
One-click install
npx skills add https://github.com/PlazaCC/antes-da-tela --skill middlewares-plazacc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middlewares
Source: https://github.com/PlazaCC/antes-da-tela/tree/main/.agents/skills/middlewares
Command: npx skills add https://github.com/PlazaCC/antes-da-tela --skill middlewares-plazacc

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about middlewares

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create tRPC middleware that authenticates users and extends the request context?

To create tRPC middleware for authentication, validate the incoming context user and call opts.next() with a narrowed ctx to guarantee downstream procedures receive a non-nullable user object. This pattern safely extends the request context for authorized server procedures.

What is the best way to compose reusable tRPC middleware chains?

Compose reusable tRPC middleware chains by using .concat() to combine existing middleware and .unstable_pipe() to extend chains for ordered context enrichment. This approach reduces boilerplate and prevents common composition errors in server procedures.

Does tRPC v11 support request timing and logging middleware for observability?

Yes, tRPC v11 supports request timing and logging middleware for observability. You can implement middleware patterns to measure request duration and create integration points for OTEL tracing to avoid silent internal errors during procedure execution.

Why does my tRPC middleware throw a runtime error or security issue when extending ctx?

Runtime errors or security issues when extending ctx usually occur from incorrect typing or failing to properly return opts.next(). Explicitly call and return opts.next() with safe context extension typing to ensure correct middleware execution flow.

Can I build an adminProcedure in tRPC that enforces role-based authorization?

Yes, you can build an adminProcedure in tRPC that enforces role-based authorization by creating middleware to check user roles within the request context. This guarantees non-nullable user context and throws an UNAUTHORIZED TRPCError when permissions are insufficient.