middleware

View as MarkdownOpen in Claude

Create a Hono-compatible middleware function that validates incoming requests against the configured auth methods. Unauthorized requests receive a 401 Unauthorized JSON response.

Parameters

None.

Returns

(c: any, next: () => Promise<void>) => Promise<Response | void> — A middleware function suitable for use with Hono’s app.use().

Example

1import { AuthHandler } from '@signalwire/sdk';
2import { Hono } from 'hono';
3
4const auth = new AuthHandler({
5 bearerToken: process.env.AUTH_TOKEN,
6});
7const app = new Hono();
8
9// Protect all routes
10app.use('*', auth.middleware());
11
12app.get('/', (c) => c.json({ status: 'ok' }));