***

title: middleware
slug: /reference/typescript/agents/configuration/auth-handler/middleware
description: Create a Hono-compatible middleware that rejects unauthorized requests.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

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**

```typescript {10}
import { AuthHandler } from '@signalwire/sdk';
import { Hono } from 'hono';

const auth = new AuthHandler({
  bearerToken: process.env.AUTH_TOKEN,
});
const app = new Hono();

// Protect all routes
app.use('*', auth.middleware());

app.get('/', (c) => c.json({ status: 'ok' }));
```