After writing about the Git-backed CMS stack, Better Auth deserves its own post.
In that architecture, auth is not a small detail. The editor needs real users, sessions, roles, invitations, audit trails, Git commit attribution, and a permissions model that goes beyond “one shared admin password”.
Better Auth is one of the most interesting open-source options for that layer.
The short version:
Better Auth = embedded TypeScript auth framework, not a hosted auth server
That distinction matters.
It is not Keycloak, Logto, Authentik, or a standalone identity provider you run as a separate product. It is also not Firebase Auth as a managed SaaS. It is a library/framework you mount inside your own TypeScript application.
What is Better Auth?
Better Auth describes itself as a framework-agnostic authentication and authorization framework for TypeScript.
The repo I checked was:
Package version: 1.7.7
CLI package: [email protected]
License: MIT
Checked commit: 0e1a9c8413ff048a617cad81ab67175933ca8c7a
Commit date: 2026-10-03
The core package is better-auth. The CLI package is now published as auth, with commands such as:
npx auth@latest generate
npx auth@latest migrate
npx auth@latest check
npx auth@latest create-admin
The core idea is simple:
- Create an auth instance in your app.
- Mount its request handler under
/api/auth/*. - Connect a database.
- Enable the auth methods and plugins you need.
- Use the generated client methods from your frontend.
Example shape:
import { betterAuth } from "better-auth";
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
});
Then a Hono app can mount it directly:
import { Hono } from "hono";
import { auth } from "./auth";
const app = new Hono();
app.all("/api/auth/*", (c) => auth.handler(c.req.raw));
export default app;
That Web Request/Response shape is why it fits modern runtimes: Hono, Astro, Next.js, SvelteKit, React Router, Nuxt, Express, Fastify, Workers, Bun, Deno, and Node-style servers.
What It Provides
Better Auth starts with the normal primitives:
- email/password sign-up and sign-in;
- social login providers such as GitHub, Google, Apple, Discord, and many others;
- cookie-based sessions;
- session listing and revocation;
- password reset and email verification workflows;
- rate limiting;
- trusted origins and cookie controls;
- schema generation and migrations;
- typed server and client APIs.
Then the plugin ecosystem adds the parts that make it more than “just login”:
| Plugin / Package | Why It Matters |
|---|---|
| Admin | Admin users, user management, roles, bans, impersonation |
| Organization | Organizations, members, teams, roles, permissions |
| Passkey | WebAuthn/passkey login |
| Two Factor | 2FA flows and backup-code behavior |
| API Key | API-key auth for programmatic access |
| SSO | SAML/OIDC-style SSO workflows |
| OAuth Provider | Let your app act as an OAuth provider |
| MCP | Auth support for MCP-style agent integrations |
| JWT / Bearer | Token-oriented API patterns |
| Magic Link / Email OTP | Passwordless auth flows |
| Username / Phone Number | Alternative identifiers |
| Stripe | Billing/auth integration patterns |
| Redis Storage | Secondary storage for short-lived auth data |
That plugin model is the reason I keep mentioning Better Auth in Cloudflare app posts. It solves the application-user problem without forcing the whole product into a hosted auth SaaS.
Database and Runtime Model
Better Auth usually needs a database.
The core tables cover users, sessions, accounts, and verification records. Plugins can add their own tables. For example, organizations and admin features need more schema than plain email/password auth.
Supported paths include:
| Storage Path | Notes |
|---|---|
| Built-in relational adapters | SQLite, PostgreSQL, MySQL, MSSQL through the Kysely-backed path |
| Drizzle adapter | Works with Drizzle schemas and several SQL providers |
| Prisma adapter | Uses your Prisma client/schema |
| MongoDB adapter | MongoDB-backed auth storage |
| Memory adapter | Useful for tests/dev, not durable production auth |
| Redis secondary storage | Optional short-lived/session/rate-limit related storage |
There is also stateless session support, but that is not the path I would design around for a CMS with organizations, admin, invitations, and audit expectations. Most serious plugin combinations need a database.
For Cloudflare, the interesting shape is:
Hono Worker + Better Auth + D1
The docs explicitly show Cloudflare D1 with programmatic migrations because D1 is accessed through a Worker binding rather than a normal CLI database connection.
Cloudflare Notes
Better Auth can work well on Cloudflare Workers, but there are important details.
For Hono on Workers, the docs call out that Better Auth uses AsyncLocalStorage. That means Wrangler needs a compatibility flag:
{
"compatibility_flags": ["nodejs_compat"]
}
Or, if you only need AsyncLocalStorage:
{
"compatibility_flags": ["nodejs_als"]
}
For rate limiting behind Cloudflare, configure the client IP header carefully:
export const auth = betterAuth({
advanced: {
ipAddress: {
ipAddressHeaders: ["cf-connecting-ip"],
},
},
});
For CORS, do not use wildcard origins with credentialed auth requests. Configure the same explicit origin in Hono CORS middleware and in Better Auth trustedOrigins.
Field Test
I did not install the full monorepo dependencies or run the entire test suite. This repo includes many packages, adapters, demos, and integration tests for PostgreSQL, MySQL, MongoDB, Redis, MSSQL, Cloudflare/D1 behavior, and multiple runtimes. A full test run is closer to library-maintainer work than a useful self-hosting smoke test.
I did run a small package/CLI check.
The current published package metadata reports:
better-auth: 1.7.7
auth CLI: 1.7.7
license: MIT
On the system Node version:
Node: v18.19.1
npx auth@latest --help failed because the CLI and several dependencies require newer Node versions. The visible failure came from a modern Node API import:
SyntaxError: The requested module 'node:util' does not provide an export named 'styleText'
Then I reran the CLI with temporary Node 24:
npx -y -p node@24 -p auth@latest -c 'node --version && auth --help'
That worked and printed the Better Auth CLI command list:
ai
create-admin
check
init
migrate
generate
secret
info
login
logout
mcp
upgrade
Practical takeaway:
Use Node 22.12+ for the CLI.
Do not expect old Node 18 environments to run current Better Auth tooling cleanly.
Why I Like It for the Git-Based CMS Stack
For the Git-backed offline CMS idea, Better Auth fits the authenticated editor layer.
The CMS needs:
- an admin role;
- author/editor roles;
- user-owned drafts;
- publish permissions;
- media upload permissions;
- audit history;
- optional OAuth login;
- session revocation;
- future organizations or teams.
Better Auth already has the right conceptual pieces:
| CMS Need | Better Auth Piece |
|---|---|
| Editor login | Email/password or social login |
| Multi-user app | Organization plugin |
| Admin panel permissions | Admin plugin |
| API access | API Key or Bearer/JWT plugins |
| Secure editor sessions | Cookie sessions, revocation, freshness |
| Cloudflare Worker API | Hono integration |
| Cloudflare storage | D1 through Worker binding |
| Future passkeys | Passkey plugin |
I would still keep Cloudflare Access as an optional outer gate for a private deployment.
But I would not use Cloudflare Access as the whole CMS auth model. Better Auth is where app roles, session state, and user-level permissions should live.
Better Auth vs Auth.js, Firebase Auth, Logto, and PocketBase
This is the part that gets confusing, because “auth” tools solve different layers.
| Tool | Best Mental Model |
|---|---|
| Better Auth | Embedded TypeScript auth framework inside your app |
| Auth.js / NextAuth | Auth library historically centered around Next.js-style app auth |
| Firebase Auth | Managed SaaS auth service |
| Supabase Auth | Managed/self-hostable auth tied to Supabase/Postgres ecosystem |
| Logto | Standalone identity provider product |
| Authentik / Keycloak | Full identity provider / SSO platform |
| PocketBase Auth | Auth built into the PocketBase backend |
| Cloudflare Access | Zero-trust perimeter / app access gate |
Better Auth is strongest when you are already building a TypeScript app and want auth to be part of that app.
It is weaker if you want a standalone company-wide identity server with a polished admin portal for many unrelated apps. In that case, Logto, Authentik, or Keycloak are more natural.
It is also not a managed SaaS. If you use Better Auth, you own:
- database setup;
- migrations;
- email delivery provider;
- OAuth provider credentials;
- cookie/domain settings;
- deployment/runtime compatibility;
- backup and recovery.
That is exactly why it fits FOSS/self-hosting builders, but it is not “zero ops”.
Where It Fits
Use Better Auth when:
- your app is TypeScript;
- you want auth inside your codebase;
- you want typed server/client auth APIs;
- you want open-source auth without building everything yourself;
- you need organizations, admin, passkeys, 2FA, API keys, or SSO over time;
- you are comfortable owning the database and migrations.
Avoid it when:
- you want a ready standalone identity server;
- you want a no-code admin console for non-developers;
- your app is not JavaScript/TypeScript;
- you do not want to manage email, OAuth credentials, database schemas, and cookie details;
- you only need Cloudflare Access in front of one private admin page.
FAQ
Is Better Auth self-hosted?
Yes, but not like a Docker app.
Better Auth is self-hosted because it runs inside your own application and stores data in your own database. There is no Better Auth server container to deploy by itself for normal use.
Think:
self-hosted library/framework
not standalone identity server
Does Better Auth need a database?
For most real apps, yes.
It can operate in stateless modes for narrower use cases, but the normal path stores users, sessions, accounts, verification records, and plugin data in a database.
For the Git-based CMS idea, I would use D1 on Cloudflare or SQLite/Postgres in a local stack.
Can Better Auth run on Cloudflare Workers?
Yes, with the right runtime setup.
The Hono integration works through standard Request and Response objects, and Cloudflare Workers can provide the API runtime. The main gotchas are:
- enable
nodejs_compatornodejs_als; - use D1 through Worker bindings;
- run D1 migrations programmatically or through your deployment flow;
- configure
trustedOrigins; - handle credentialed CORS correctly;
- use
cf-connecting-ipor trusted proxy configuration for IP-aware rate limits.
Is Better Auth a replacement for Firebase Auth?
It can replace Firebase Auth for an app where you want to own the auth database and keep auth inside your TypeScript backend.
But it is not a hosted drop-in SaaS. Firebase Auth gives you a managed service. Better Auth gives you framework code, adapters, plugins, and control.
So the tradeoff is:
Firebase Auth = managed convenience
Better Auth = app-owned control
Is Better Auth a replacement for Logto, Authentik, or Keycloak?
Usually no.
Logto, Authentik, and Keycloak are standalone identity platforms. Better Auth is embedded into your application.
For one custom TypeScript product, Better Auth can be simpler. For many apps sharing one central identity provider, SSO policies, enterprise federation, and admin-console workflows, a standalone IdP can be a better fit.
What are similar open-source alternatives?
Yes, Logto is one of the relevant open-source alternatives, but it sits in a different category.
The useful way to compare them is by product shape:
| Category | Projects | Best Fit |
|---|---|---|
| Embedded TypeScript auth | Better Auth, Auth.js | You are building a TypeScript app and want auth inside your codebase |
| Standalone identity provider | Logto , Authentik , Keycloak , Ory Kratos | You want a separate auth/identity service shared by multiple apps |
| Backend platform with auth | Supabase Auth, Appwrite, PocketBase | You want auth bundled with a broader backend/database/storage platform |
| Access gateway | Authelia, oauth2-proxy, Cloudflare Access | You want to protect existing apps at the reverse-proxy or perimeter layer |
My practical read:
- Use Better Auth when the app is TypeScript and auth should be part of the application.
- Use Logto when you want a modern standalone OIDC/OAuth identity provider with SaaS/team-app features.
- Use Authentik when you want a self-hosted SSO/IdP with lots of protocol and proxy-provider flexibility.
- Use Keycloak when you need a mature, heavy-duty enterprise IAM platform.
- Use Ory Kratos when you want API-first identity building blocks and are comfortable composing Ory services.
- Use PocketBase/Appwrite/Supabase when you want auth as part of a full backend platform.
- Use Authelia/Cloudflare Access/oauth2-proxy when the main goal is protecting apps, not building app-native user roles.
For the Git-based CMS editor, I would still choose Better Auth first. It gives the app its own users, roles, sessions, and permissions without requiring a separate identity platform. If that CMS later needed to integrate with company-wide SSO, then Logto, Authentik, Keycloak, or Ory would become more relevant.
Is Better Auth better than Cloudflare Access?
They solve different problems.
Cloudflare Access is excellent as an outer gate:
Can this person reach the app?
Better Auth handles application identity:
Who is this user inside the app, and what can they do?
For the CMS editor, I would use both only when needed:
Cloudflare Access outside
Better Auth inside
Which database would I use for the Cloudflare CMS idea?
I would use D1 for the Cloudflare-native version.
Better Auth plus Hono plus D1 fits the proposed editor API:
Hono Worker
Better Auth
D1 auth tables and CMS metadata
R2 media uploads
Git provider API for publishing
Cloudflare Pages for static output
For a homelab/local version, I would use SQLite or Postgres.
What Node version should I use?
Use modern Node.
The current [email protected] CLI declares node >=22.12.0. In my local check, Node 18 failed while temporary Node 24 succeeded.
For new projects, start with Node 22 LTS or newer.
What would I enable first?
For the Git-backed CMS editor:
betterAuth({
emailAndPassword: { enabled: true },
plugins: [
admin(),
organization(),
],
});
Then add social login, passkeys, API keys, or SSO only when the product actually needs them.
Auth is security-sensitive. Start small, keep the schema understandable, and add plugins deliberately.
Comments