bill92
bill924w ago

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),
});
1 Reply
avvo
avvo4w ago
just create new procedures that are only used in the billing router

Did you find this page helpful?