Skip to content

Commit 9e15a33

Browse files
authored
docs: fix incorrect middleware execution order in Hono adapter (#42)
The Skip behavior section claimed that route-level middleware runs before app-wide middleware. This is wrong -- Hono runs middleware in registration order, so app.use('*', ...) always runs first. The documented pattern (app-wide 'user' + route-level 'secret') would not work as described: the app-wide middleware runs first, sets the context, and the route-level middleware skips. Replaced the section with a note about the actual execution order and a pointer to the per-route auth pattern, which works correctly.
1 parent 2fb043e commit 9e15a33

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

docs/hono-adapter.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,11 @@ export default { fetch: app.fetch }
8181

8282
## Skip behavior
8383

84-
If a previous middleware already set `c.var.supabaseContext`, subsequent `withSupabase` calls skip auth. This enables a pattern where route-level middleware overrides the app-wide default:
84+
If a previous middleware already set `c.var.supabaseContext`, subsequent `withSupabase` calls skip auth. This matters when multiple `app.use` middlewares overlap on the same path — the first one to set the context wins.
8585

86-
```ts
87-
const app = new Hono()
88-
89-
// App-wide: require user auth
90-
app.use('*', withSupabase({ allow: 'user' }))
86+
**Important:** Hono runs middleware in registration order (`app.use` before route-level middleware). An `app.use('*', ...)` middleware will always run before inline route middleware, so the skip-if-set pattern cannot be used to make a route stricter than the app-wide default.
9187

92-
// This route needs secret auth instead.
93-
// The route-level middleware runs first, sets the context,
94-
// and the app-wide middleware skips.
95-
app.post('/webhook', withSupabase({ allow: 'secret' }), async (c) => {
96-
const { supabaseAdmin } = c.var.supabaseContext
97-
// ...
98-
})
99-
```
88+
For routes that need different auth than the rest of the app, use per-route middleware without an app-wide middleware (see the "Per-route auth" section above).
10089

10190
## CORS
10291

0 commit comments

Comments
 (0)