-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
Allow Users to Specify Types for JWT Middleware Payload #2492
Comments
Hi @NicoPlyley, Thank you for raising the issue. This is related to #2249, #2313. I'm thinking about this a long time. We are going to resolve this issue soon. |
Thank you @NicoPlyley and @yusukebe this will solve my issues as well! |
@yusukebe Any chance to make |
Yes. I want to make it not global in the future. The following way should be recommended: // factory.ts
import { drizzle, DrizzleD1Database } from 'drizzle-orm/d1'
import { Hono } from 'hono'
export const createHonoWithDB = () => {
const app = new Hono<{
Bindings: {
D1: D1Database
}
Variables: {
db: DrizzleD1Database
}
}>()
app.use(async (c, next) => {
c.set('db', drizzle(c.env.D1))
await next()
})
return app
} // app.ts
import { createHonoWithDB } from './factory'
const app = createHonoWithDB()
app.get('/', (c) => {
c.var.db.select() //...
})
export default app But, though it's a types matter, it causes a little breaking change. So I'm cautious. |
What is the feature you are proposing?
When using the JWT middleware, end users currently cannot specify the type for the payload. The context variable is set to
jwtPayload: any
, and there have been multiple discussions by people on Discord asking how to set the types. It cannot be overridden in ContextVariableMap, so the only way to set it is by casting.I am proposing that we either incorporate generic type parameters, for example,
jwt<MyPayloadType>({ secret: '123' })
, which can be backwards compatible.Or we remove the following:
And force the user to set the context variables themselves.
The text was updated successfully, but these errors were encountered: