Skip to content

feat(auth): honour the owner's Better Auth database and sign-in methods (#1052 S5) - #1057

Merged
jimhoyd merged 2 commits into
mainfrom
claude/auth-own-database-1052
Sep 30, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/auth-own-database-1052

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Part of #1052 (slice S5: Better Auth bring-your-own database).

What changes

  • auth({database}) takes either the bundled SQLite file's path (as before) or the owner's own Better Auth database (anything Better Auth's database option accepts). An owner database goes to Better Auth unchanged. betterAuth.database is refused and points to database.
  • With an owner database, the SQLite-only machinery is skipped: no holdServerLock, no WAL/permission/network-FS checks, no pendingMigrations check and no migrations. Better Auth's own checkSchema still runs when its adapter has one. Activation emits one extension_warning (ownerDatabaseWarning) that names what becomes the owner's responsibility: schema and migration state, backups, single-writer or multi-server rules, and access control.
  • urlcode-auth migrate/create-user/find-user refuse with exit 2 and a clear message while data/auth.owner-database exists. host() writes that marker on a non-hermetic load with an owner database and removes it when host.mjs switches back to SQLite. The CLI cannot read host.mjs, so before the first non-hermetic host load (validate with a pin, dev, serve) it cannot know the owner's choice. That limitation is in the docs.
  • Hermetic runs with an owner database: auth({testDatabase: ({data}) => <fresh db>}) is called once per run. Without it, activation refuses (hermeticOwnerDatabaseRefusal). If it returns the live database object, activation also refuses. A hermetic registration never serves database.
  • Seeds now go through internalAdapter.createUser + linkAccount (Better Auth's API, with hooks), so they work on any adapter.
  • Email/password is a default rather than forced. With emailAndPassword.enabled: false, /sign-in/email and /change-password answer 404, and signUp: true and an auth seed are refused.

Contract check with an owner database (memoryAdapter test)

  • 503 auth_unavailable on a storage failure on the gate, /list-sessions and /sign-out, with no Set-Cookie. The session survives an unconfirmed sign-out.
  • The path allowlist gives 404 and the 1 MiB body bound gives 413.
  • Not re-proven with an owner adapter: the per-adapter busy/lock semantics. Those belong to the owner's database.

Tests

New packages/auth/test/owner-database.test.ts uses Better Auth's upstream memoryAdapter. It covers an owner-database site serving sign-in (plus the warning and the 503/sign-out/allowlist/bounds contract), the hermetic refusal without an isolated database, the hermetic run with one (the seed goes into the test database and the live one stays untouched), email/password disabled, and the CLI refusal and its lifting. All existing SQLite-path tests pass unchanged.

npm run verify, npm run test:package, npm run audit:packages (auth: 28372 packed / 91455 unpacked / 14 files, within budget) and npm run test:proof pass locally.

Docs

Auth README (new "Your own database" section), SECURITY, CHANGELOG and llms.txt; root llms.txt; RIM-EXT-HERMETIC-001 card (plus the fixture); EXTENSIONS hermetic section; READINESS test data; FRAMEWORK table.

🤖 Generated with Claude Code

…ds (#1052 S5)

auth({database}) also takes the owner's own Better Auth database (an adapter,
dialect or pool), passed to Better Auth unchanged. With one, the SQLite-only
lock, WAL/file checks, table check and migrations do not apply, activation
logs one warning naming what is the owner's, and urlcode-auth migrate,
create-user and find-user refuse. A hermetic run serves the owner's
testDatabase factory's isolated database and is refused without one; it
never falls back to live data. Seeds go through Better Auth's internal
adapter. Email and password is a default rather than forced.

Part of #1052.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit 3728092 into main Sep 30, 2026
26 checks passed
@jimhoyd
jimhoyd deleted the claude/auth-own-database-1052 branch September 30, 2026 15:23
jimhoyd added a commit that referenced this pull request Sep 30, 2026
…1061)

A resolved merge committed packages/auth/CHANGELOG.md with its conflict markers still in it (via #1057), and no check
failed: code conflicts break the typecheck, but Markdown, JSON and YAML conflicts passed everything. Removed from main
by #1055.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant