Mount Better Auth without an adapter
Hono or Cloudflare Workers
Better Auth · Module
auth.handler is Better Auth's Web Standard request handler. Mount it on a catch-all route matching the configured auth base path and pass the incoming Request to receive a Response.
The handler is the request entry point for Better Auth. Mount it on a catch-all route matching the configured base path, pass the incoming Web Standard Request to it, and return the resulting Response.
auth.handler(request)| Name | Type | Description |
|---|---|---|
request | Request | Incoming Web Standard HTTP request containing the method, URL, headers, and optional body. |
A Web Standard Response generated by Better Auth.
c.req.raw to the handler./api base path, define the auth route as /auth/* within that application./api/auth.import { auth } from "./auth";
export async function GET(request: Request) {
return auth.handler(request);
}
export async function POST(request: Request) {
return auth.handler(request);
}Forward GET and POST Web Standard requests to Better Auth from a catch-all authentication route.
Hono or Cloudflare Workers
Framework catch-all API route
Custom base path deployment
auth.handler?auth.handler is the server-side request handler exposed by a Better Auth instance. A framework route passes it a Web Standard Request, and the returned Response is sent back to the client.
Follow-up: How would you mount it in Hono? Use app.all on the matching auth path and call auth.handler(c.req.raw).
Mount the handler on a catch-all authentication route and export it for the HTTP methods your framework supports. The route should match the configured Better Auth base path, which defaults to /api/auth.
Follow-up: What happens if the route does not match the base path? Requests may not reach Better Auth, so the configured route pattern and basePath must be aligned.
auth.handler directly?Hono and Better Auth both use the Web Standard Request and Response APIs, so Hono can call the handler directly without an adapter. The raw request is supplied through c.req.raw.
Follow-up: Why is a raw request needed? It preserves the Web Standard request object expected by Better Auth instead of passing Hono's context wrapper.
basePathRequestResponseHonoc.req.raw