For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
        • AuthHandler
          • expressMiddleware
          • getAuthInfo
          • hasApiKeyAuth
          • hasBasicAuth
          • hasBearerAuth
          • middleware
          • validate
          • verifyApiKey
          • verifyBasicAuth
          • verifyBearerToken
        • ConfigLoader
        • Environment Variables
        • Logging
        • PromptManager
        • SchemaUtils
        • ServerlessAdapter
        • SessionManager
        • SslConfig
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsConfigurationAuthHandler

middleware

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

validate

Next
Built with

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
booleanDefaults to false

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().

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 — unauthorized returns 401
10app.use('*', auth.middleware());
11
12app.get('/', (c) => c.json({ status: 'ok' }));
13
14// Or allow unauthenticated access through
15app.use('/public/*', auth.middleware(true));