Krishna
Krishna3mo ago

middleware’s for routers

I am using middleware’s in procedures presently. I want to use middleware’s for the whole child router to handle multi-tenancy & role-permission handling. Is there a way to add middleware’s directly to child routers?
4 Replies
Nick
Nick3mo ago
Just define a base procedure next to your router and use it for all procedures const middlewaredProcedure = publicProcedure.use(...)
Krishna
KrishnaOP3mo ago
I want different procedures for different routers. Rather than having to check in every sub-nested route if the correct procedure is applied, a router level config would have been great. For example public, private & admin. Difficult to check it at individual route level. The thing is confidence, as codebase & team grows, it becomes a little challenging to ensure correct procedures are applied everywhere
Nick
Nick3mo ago
I routinely define procedures either in the same file as a router or in its feature folder. By convention I only use the procedure defined for each router Not sure what benefit doing this at the router level would give, you still have to define it in the same file
Krishna
KrishnaOP2mo ago
Hi! What if there are subroutes & I want to prevent something at parent level. ofcourse we can have one procedure for each router & then build the procedures in such a way that they use the parent procedure. Just that allows for mistakes if the pattern is not followed. But one-to-one router-procedure mapping is interesting & I will go with that for now. Thanks 🙂

Did you find this page helpful?