middleware
Create a Hono-compatible middleware function that validates incoming requests
against the configured auth methods. Unauthorized requests receive a
401 Unauthorized JSON response by default; pass optional: true to let them
pass through without blocking.
Parameters
optional
When true, unauthenticated requests are allowed through instead of being
rejected with a 401. Useful for routes that expose richer data to
authenticated callers but still serve unauthenticated traffic.
Returns
(c: any, next: () => Promise<void>) => Promise<Response | void> — A
middleware function suitable for use with Hono’s app.use().