Skip to content
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

Middleware Implementation Limitation in Hono Routing #96

Open
kbventures opened this issue Mar 19, 2025 · 2 comments
Open

Middleware Implementation Limitation in Hono Routing #96

kbventures opened this issue Mar 19, 2025 · 2 comments
Assignees

Comments

@kbventures
Copy link
Contributor

kbventures commented Mar 19, 2025

Original conversation: #90 (comment)

Summary:
Issue: The route() method in Hono only accepts a maximum of 2 parameters, making it impossible to explicitly add middleware like authMiddleware within route().

Potential solution:

Middleware array:
https://github.com/honojs/middleware/tree/main/packages/zod-openapi#configure-middleware-for-each-endpoint

@abdulqshabbir
Copy link
Contributor

abdulqshabbir commented Mar 23, 2025

Hi @kbventures, would this work as a potential solution (syntactically)?

instead of:

app.use('/*', authMiddleware);
app.route('/profiles', protectedProfileRoutes);
app.route('/teams', protectedTeamRoutes);
app.route('/roles', privateRolesRoutes);

something like this:

const protectedApp = app.use(authMiddleware)
protectedApp.route('/profiles', protectedProfileRoutes);
protectedApp.route('/teams', protectedTeamRoutes);
protectedApp.route('/roles', privateRolesRoutes);

Having like two "top-level" hono apps one that is public and one that is private (private would inherit from the public one with the addition of authMiddleware requiring an auth_token).

Or we can move the authMiddleware into the middleware array of the createRoute function?

@madcampos
Copy link
Collaborator

As we will have to define all routes using openapi already to document them, I do think we can just try the middleware array and see if it works, if not, then we can think about other approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants