Closed jonasgroendahl closed 1 year ago
Hi,
thanks for asking !
One warning up front, taken from: https://www.fastify.io/docs/latest/Reference/Middleware/ Starting with Fastify v3.0.0, middleware is not supported out of the box and requires an external plugin such as @fastify/express or @fastify/middie.
Then on to some more details:
Security handlers are attached as preHandler. So anything you add to the routes that runs before preHandler (see hooks) will run before the security handler. You can tailor the behaviour of such a "pre-preHandler" using https://github.com/seriousme/fastify-openapi-glue#openapi-extensions.
Alternatively you could have your securityHandler call a middleware function before or after it runs the actual security function (so basically wrap the security handler), or you could have the service handler call a middleware function before it starts to do its actual work.
Last alternative, that I know of, is that you have your middleware take full control of security handling as well and don't provide fastify-openapi-glue with a security.js.
Hope this helps !
Kind regards, Hans
Thanks for the reply :) i have an idea now, cheers!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
Not necessarily an issue but how I run some middleware for some routes? and can I run the middleware before / after the securityScheme function runs?