tRPCttRPC
Powered by
bill92B
tRPC•11mo ago•
2 replies
bill92

Use middleware on the router level

Is it possible to apply a middleware to the router level?

I have 4 routers and I would like to apply different middleware to each of them

// Core router
const coreApiRouter = router({
  billing: billingRouter,
  customer: customerRouter,
  appointment: appointmentRouter,
  note: noteRouter,
});
// Core router
const coreApiRouter = router({
  billing: billingRouter,
  customer: customerRouter,
  appointment: appointmentRouter,
  note: noteRouter,
});


I was thinking on doing something like the above but it's not working

const coreApiRouter = router({
  billing: procedure.use(({ next }) => next()).concat(billingRouter),
});
const coreApiRouter = router({
  billing: procedure.use(({ next }) => next()).concat(billingRouter),
});
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Any guidance on adding middleware at the router level?
TimKleierTTimKleier / ❓-help
16mo ago
Can middleware be used on a router?
aryzingAaryzing / ❓-help
3y ago