Skip to main content

Middleware

Middleware type for Express-compatible request handlers.
type Middleware = RequestHandler | RequestHandlerAndRouter
A middleware can be either:
  • A standard Express RequestHandler
  • A RequestHandlerAndRouter object containing both middleware and a router

RequestHandlerAndRouter

Combined middleware and router configuration.
middleware
RequestHandler
required
Express request handler middleware function
router
Router
required
Express router instance

WebMiddleware

Middleware type for web-based request handling.
type WebMiddleware = (
  request: Request,
  context: WebMiddlewareContext
) => Promise<Response | void> | Response | void
A function that processes web requests with access to authentication context. Can return:
  • A Response object to send immediately
  • void to continue to the next middleware
  • A Promise resolving to either of the above
request
Request
required
The incoming web request
context
WebMiddlewareContext
required
Context object containing authentication information and utilities

WebMiddlewareContext

Context object passed to web middleware functions.
auth
AuthInfo
Current authentication information, if available
auth.token
string
required
The access token
auth.clientId
string
required
The client ID associated with this token
auth.scopes
string[]
required
Scopes associated with this token
auth.expiresAt
number
When the token expires (in seconds since epoch)
auth.resource
URL
The RFC 8707 resource server identifier for which this token is valid
auth.extra
Record<string, unknown>
Additional data associated with the token
setAuth
(auth: AuthInfo) => void
required
Function to update the authentication information in the context

Build docs developers (and LLMs) love