Closed fahadali503 closed 2 years ago
It's not possible. Foal is not designed that way. The only thing that you can do is to apply an Express middleware globally to all your application: https://foalts.org/docs/cookbook/expressjs/#pre-and-post-express-middlewares.
Thanks for the response. One more question, can we access userId in express middleware when using @RequireJWT() hook.
No, it's not possible because all the hooks and the controllers are loaded/executed after the pre-middlewares. In which case would you like to access the userId in one of your middlewares?
I mean when we use @JwtRequired() hook, we get userId in controller. My question is that if i use express middleware, will i get the userId from the request body.
No, you won't. Because all the application (controllers, hooks and services) are separated from Express. Foal is not designed to be used with Express middlewares.
The only thing that you can do is to put a middleware that is executed before the execution of the application, ie before the execution of the hooks and controllers. This feature only exists for special cases to support Nuxt or Next middlewares for example.
Looks like this question has been answered. I'm closing the issue 👍