Skip to content

fix(auth): a passing local-review validate no longer prints Better Auth's schema-check error (#1013) - #1017

Merged
jimhoyd merged 1 commit into
mainfrom
claude/auth-schema-noise-1013
Sep 30, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/auth-schema-noise-1013

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1013

Cause

Better Auth's createBetterAuth starts ctx.checkSchema() as soon as the instance's context resolves and never awaits it; on rejection it logs Could not validate the database schema. Check your database connection. A validate --local-review run activates the auth extension on a throwaway database (the hermetic migrate already created the tables), then closes the host immediately. The instance's close() closed the SQLite connection while that check was still in flight, so the check failed on the closed connection and logged the error, although nothing was wrong. It was not an ordering problem with table creation and not a logger default.

Fix

createAuthExtension's activate now awaits (await auth.$context).checkSchema?.() right after constructing the instance. The check is a shared promise, so Better Auth's own background call resolves at the same time and the connection is closed only afterwards. Better Auth's logging is untouched: a real schema problem still logs, and it now also refuses activation (the catch releases the lease and closes the database) rather than failing each request later.

Evidence

  • Reproduced with the CLI on an auth site: validate --local --local-review exited 0 and printed the ERROR line on stderr; after the fix it prints only the local_review event.
  • New test/auth-validate-stderr.test.ts runs the real CLI: a passing local-review validate prints nothing matching ERROR|Could not validate|schema on stderr, and a pinned (PROJECT_SHA256) validate on an unmigrated data/ still exits 1 with Better Auth's tables are not initialized (...). The first assertion fails with the fix reverted.
  • npm run verify and npm run test:package pass locally (macOS).

Limitations

  • Better Auth's SQLite schema check diffs missing tables and columns, which pendingMigrations already refuses first; a column type mismatch is only a Better Auth warning, not a check failure, so this PR does not change how that is reported.
  • The auth README notes that activation waits for the schema check.

🤖 Generated with Claude Code

… is quiet (#1013)

Better Auth starts a schema check when an instance is constructed and never
awaits it. A short run such as `urlcode validate --local-review` closed the
auth database before that check finished, so the check failed on the closed
connection and Better Auth logged "Could not validate the database schema"
to stderr while validate passed. Activation now awaits the check: the run
closes the connection only after it has finished, and a real schema problem
refuses activation instead of failing each request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 30, 2026 00:23
@jimhoyd
jimhoyd merged commit e5e725c into main Sep 30, 2026
23 checks passed
@jimhoyd
jimhoyd deleted the claude/auth-schema-noise-1013 branch September 30, 2026 00:27
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.

Local-review validate on an auth site prints Better Auth's "Could not validate the database schema" while passing

1 participant