Mount the handler
Useapp.on to handle both GET and POST requests on the /api/auth/* path and forward them to auth.handler.
server.ts
CORS configuration
Use thecors middleware from hono/cors. Register it before your routes so cross-origin requests are handled before they reach the auth endpoints.
server.ts
Session middleware
Add a global middleware that fetches the session and stores theuser and session objects in Hono’s context. This lets every downstream route access them without repeating the session lookup.
server.ts
Accessing session in routes
Cross-domain cookies
By default, all Better Auth cookies useSameSite=Lax. If your client and server share a subdomain, enable cross-subdomain cookies in your auth config:
auth.ts
SameSite=None), configure the default cookie attributes:
auth.ts
auth.ts
Hono client configuration
When using the Hono RPC client (hono/client) to call Better Auth-protected endpoints, set credentials: "include" so the client forwards cookies on cross-origin requests.
lib/api.ts
credentials: "include" must be paired with credentials: true in the server’s CORS configuration, and the origin must be set to a specific domain (not *).