wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Allow specifying middleware for individual and groups of Operations (Action, Query) on the server

Open Martinsos opened this issue 1 year ago • 5 comments

If you want to execute some logic that is common for a group of Operations (and maybe also APIs), there is no simple way to do it -> we do have customMiddleware for APIs and api namespaces, but not for Operations or groups of Operations. You might want this to do some auth checks, maybe check the role of the user, or maybe inject some additional information that all of these need, ... .

So, what we want is enable users to provide middleware that executes for a group of Operations / APIs. Maybe we can specify this by grouping them somehow, or by specifying the route prefix (although for Operations, their route is implementation detail right now, so something would have to change there). We should of course consider if we can utilize existing expressjs functionality vs reimplementing too much of this on our own, what makes more sense.

Martinsos avatar Dec 04 '24 19:12 Martinsos

This would be a nice thing to have!

JakeLo123 avatar Jan 08 '25 22:01 JakeLo123

Bumping this because it's requested a lot (@JakeLo123 also requested it again on a call today😄).

Thanks for the patience, Jake!

sodic avatar Feb 17 '25 18:02 sodic

Another user asking for this: https://discord.com/channels/686873244791210014/1348860456319586438/1348860456319586438

sodic avatar Mar 11 '25 16:03 sodic

Related: https://github.com/wasp-lang/wasp/issues/2556

Martinsos avatar Mar 17 '25 21:03 Martinsos

I imagine this middleware would also be able to update the context object. Therefore enabling use cases like https://github.com/wasp-lang/wasp/issues/2819 .

Martinsos avatar Jun 04 '25 09:06 Martinsos