Repository navigation
fix(auth): a passing local-review validate no longer prints Better Auth's schema-check error (#1013) - #1017
Merged
Conversation
… 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1013
Cause
Better Auth's
createBetterAuthstartsctx.checkSchema()as soon as the instance's context resolves and never awaits it; on rejection it logsCould not validate the database schema. Check your database connection.Avalidate --local-reviewrun activates the auth extension on a throwaway database (the hermetic migrate already created the tables), then closes the host immediately. The instance'sclose()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'sactivatenow 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 (thecatchreleases the lease and closes the database) rather than failing each request later.Evidence
validate --local --local-reviewexited 0 and printed the ERROR line on stderr; after the fix it prints only thelocal_reviewevent.test/auth-validate-stderr.test.tsruns the real CLI: a passing local-review validate prints nothing matchingERROR|Could not validate|schemaon stderr, and a pinned (PROJECT_SHA256) validate on an unmigrateddata/still exits 1 withBetter Auth's tables are not initialized (...). The first assertion fails with the fix reverted.npm run verifyandnpm run test:packagepass locally (macOS).Limitations
pendingMigrationsalready 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.🤖 Generated with Claude Code