Better Auth is a TypeScript authentication framework you host in your own application. Unlike Auth0, Okta, Clerk, or LoginRadius, it is not only a hosted identity provider integration. Your app owns the auth tables, the session cookies, and the auth endpoints.
Better Auth already documents Hono, Elysia, and Fastify adapters. DaloyJS does not need a special adapter because both libraries meet at the Web-standard boundary: Better Auth exposes auth.handler(request)and DaloyJS gives every route and hook the original Request.
The auth endpoints are Better Auth's own Request to Response handler. Normal DaloyJS API routes read the current session from request headers and enforce application authorization.
1. Install
ts
pnpm add better-auth
2. Create the auth instance
Configure Better Auth once and export the instance. Use the database adapter that matches your app. The example below keeps the database placeholder explicit because production apps should not copy a toy in-memory store into auth.
Better Auth owns all routes below /api/auth/*. Return the raw Response from a beforeHandle hook so cookies, redirects, status codes, and multiple Set-Cookie headers are preserved exactly.
Best default for database-backed sessions and OAuth callbacks.
Bun / Deno
Depends on adapter
Use only with database drivers tested on that runtime.
Cloudflare Workers
Depends on adapter
The auth handler is Web-standard, but your database adapter must also work on Workers.
Vercel
Yes
Use Node functions unless every selected adapter is edge-safe.
AWS Lambda
Yes
Use pooled or serverless database access.
Security notes
Secure deployment checklist
01configSecretBETTER_AUTH_SECRET from a real secret manager
02OrigintrustedOrigins pins browser origins
03Cookiespreserve raw Response from auth.handler
04Proxydeclare TRUST_PROXY_HOPS behind a platform edge
05Databasemigrate auth tables before traffic
Better Auth is part of your deployed app, so the auth route needs the same production posture as the rest of the API: secure secrets, trusted origins, proxy-aware URLs, preserved cookies, and database migrations.
Generate a strong BETTER_AUTH_SECRET and rotate it with the same care as a JWT signing key.
Keep trustedOrigins narrow. Do not allow arbitrary origins in production.
Preserve Better Auth's raw Response for auth endpoints. Rebuilding headers into a plain object can collapse multiple Set-Cookie headers.
When deployed behind Railway, Render, Fly.io, Vercel, Cloudflare, or another edge proxy, configure DaloyJS's proxy posture so generated URLs, cookies, rate limiting, and audit logs use the expected origin and client IP.
Put rateLimit() in front of sign-in, sign-up, password reset, and callback routes. Better Auth handles auth logic, but the API still needs abuse controls.