wasp
wasp copied to clipboard
Allow specifying middleware for individual and groups of Operations (Action, Query) on the server
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.
This would be a nice thing to have!
Bumping this because it's requested a lot (@JakeLo123 also requested it again on a call today😄).
Thanks for the patience, Jake!
Another user asking for this: https://discord.com/channels/686873244791210014/1348860456319586438/1348860456319586438
Related: https://github.com/wasp-lang/wasp/issues/2556
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 .