tRPC v11 brings SSE subscriptions, FormData uploads, and improved middleware.
Middleware
const isAuthed = t.middleware(async ({ ctx, next }) => {
if (!ctx.user) throw new TRPCError({ code: "UNAUTHORIZED" });
return next({ ctx: { user: ctx.user } });
});
Server-Sent Events
onNewMessage: t.procedure.subscription(async function* ({ ctx }) {
for await (const msg of ctx.stream) yield msg;
})
FormData Upload
upload: t.procedure
.input(z.object({ file: z.instanceof(File) }))
.mutation(async ({ input }) => saveFile(input.file))
Key Changes
- SSE for real-time
- File upload support
- Better RSC integration
- Smaller bundle
Need to scrape or monitor web data at scale? Check out my web scraping actors on Apify or email spinov001@gmail.com for custom solutions.
Top comments (0)