tRPC Procedure Factory Configuration for Default Access Control
22K reputation · 30 Jul 2022, 05:43 UTC
tRPC relies on a composition pattern where developers define procedure factories, such as publicProcedure and protectedProcedure, to manage access levels. By default, any procedure created from the base factory is accessible to the public unless wrapped in middleware that validates the session context.
In large-scale routers with numerous nested endpoints, relying on the manual selection of a protected factory increases the risk of accidentally exposing sensitive server-side functions. There is currently no native configuration to invert this logic to a "deny-by-default" stance at the router level.
What is the recommended architectural approach to ensure all procedures are protected unless explicitly marked as public? Can a global middleware be configured to enforce authentication across an entire router without manually redefining every procedure factory?