-
-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discourage usage of ContextVariableMap and provide helper ExtractEnv #2249
Comments
Hi @KilianB Sorry for the late response! I totally agree with you. We will try to avoid using MiddlewareHandler<{
Variables: {
jwtPayload: any
}
}> We have to think about whether the change would be a breaking change, but we will go ahead. |
Hey @KilianB, I'm encountering this issues with the jwt middleware. Have you used any workarounds or do you have any suggestion on how to avoid the |
Inspired on this X post I'm doing it like:
|
I was trying to go a bit further, to make some var available on the root and its child apps, but also some vars only on a child app only. And this in a type-safe manner.
creating the root app like
The root app and children will contain the Creating a child app:
but the
Am I doing something wrong? |
What is the feature you are proposing?
We currently build a large application with multiple nested routes and the need for different middleware
Where we now have 2 issues at the same time.
remoteIp
which is a global middleware is not available in any of the mounted mountedHono
instancejwtPayload
is available in all hono instances even though it is not set as the middleware is only bound to managementRoutesI believe the ContextVariableMap is really convinient, but it also provides incorrect typings and now we can not trust the IDE anymore and have to either just assume we are right or use some additional checks everywhere.
A better solution would be to provide a utility type to extract the ENV generic and let the user manually pass it down to the mounted Hono instances.
If usability is favored over correctness we should at least have a section in the docs hinting that such a type helper could be used.
The text was updated successfully, but these errors were encountered: