How to set routes that only they can access Context variables #1987
PatricioPoncini
started this conversation in
General
Replies: 1 comment 4 replies
-
This is a hot topic for me too. We are currently considering the feature to add another Env type to only a specific route. PR: #1980 type Env = {
Variables: {
foo: string
}
}
const app = new Hono<Env>()
app.get<{
Variables: {
bar: string
}
}>('/', (c) => {
const foo = c.var.foo // foo is string
const bar = c.var.bar // bar is string
return c.json(0)
}) Does this solve your problem? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm wondering if there's a way to configure routes in a manner that restricts access to certain Context variables. For instance:
In this example, using c.get(foo) within this route retrieves the value of the 'foo' key. However, this implies that the 'foo' key is available across all routes that are typed with the Env interface. How can I define a route to exclusively have the Env interface and another variable that can only be accessed from that specific route?
Because if I want to extend, for example here, it will give an error in the other routes since they are typed with Env, and this one is also, but it has the addition that I'm adding something exclusive to it.
Beta Was this translation helpful? Give feedback.
All reactions