instantcommerce / next-api-decorators

Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.
https://next-api-decorators.vercel.app
MIT License
409 stars 29 forks source link

Ability to pass extra arguments to custom middleware decorators? #567

Closed alaughlin closed 1 year ago

alaughlin commented 1 year ago

Is there a way to define a custom middleware decorator so that it could take more than just the req, res, and next function?

Ideally I'd like to invoke a custom middleware on a per-route basis like so:

MyMiddleware(SomeArgument)
Get()
async get() {...}

and MyMiddleware would be defined in a way that lets me access the SomeArgument that was passed in along with the req, res, etc

alaughlin commented 1 year ago

I should have checked the discussions, I found the answer here https://github.com/instantcommerce/next-api-decorators/discussions/361