tRPC 11.19

Last reviewed Oct 25, 2026

Export as PDF

Prompt Details

Prompt Composition

4prompts
  1. JavaScript ES2026102 lines · 3.1K tokens
  2. Node.js 24101 lines · 5.3K tokens
  3. TypeScript 746 lines · 1.5K tokens
  4. tRPC 11.1959 lines · 2.6K tokens
Total308 lines · 12.5K tokens

CWE Coverage

  • 20
  • 22
  • 59
  • 73
  • 78
  • 79
  • 88
  • 89
  • 95
  • 113
  • 117
  • 200
  • 201
  • 208
  • 209
  • 214
  • 250
  • 295
  • 297
  • 306
  • 319
  • 323
  • 330
  • 338
  • 346
  • 347
  • 352
  • 354
  • 362
  • 367
  • 377
  • 426
  • 444
  • 459
  • 471
  • 488
  • 494
  • 502
  • 524
  • 532
  • 598
  • 602
  • 613
  • 639
  • 653
  • 732
  • 770
  • 772
  • 807
  • 829
  • 838
  • 862
  • 863
  • 908
  • 915
  • 916
  • 918
  • 922
  • 942
  • 943
  • 1004
  • 1321
  • 1333

Prompt Preview

Apply the Node.js 24, TypeScript 7, and JavaScript ES2026 prompts first. These rules cover tRPC 11.19 HTTP procedures, local callers, WebSockets, and SSE. Also apply the prompt for the host framework when it mounts a tRPC adapter.

Procedures, identity, and access

  • Build a reusable authenticated procedure with t.procedure.use(...) and use it for every protected query, mutation, and subscription. A router name, meta() value, or inferred AppRouter type does not enforce access. Treat a bare t.procedure as public.
  • Verify tokens, cookies, and other credentials while constructing createContext; reject invalid or expired credentials before populating a trusted principal. Authorize each procedure's operation and selected resource against that principal, including tenant membership and object ownership. Derive privileged fields on the server instead of accepting them from .input().
  • Use .mutation() for state changes. Queries and subscription setup can be sent with GET, retried, cached, or reconnected; do not put writes with mutation-level authorization requirements in them.
  • Keep one server initTRPC configuration for routers that must share context, transformer, and error policy. Export only AppRouter as an import type to browser code; keep server modules out of client bundles and leave allowOutsideOfServer disabled.

Context, middleware, and validation

  • Account for createContext running once for an HTTP request, including a batch, and once for a WebSocket connection. Never hold a principal or tenant in process-wide mutable state. Treat