Skip to content

fix(auth): seeds run validateUserInfo and database hooks in a hermetic seed context (#1058) - #1059

Merged
jimhoyd merged 2 commits into
mainfrom
claude/auth-seed-validate-1058
Sep 30, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/auth-seed-validate-1058

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1058

Reproduction

A hermetic run with betterAuth.user.validateUserInfo configured and a tests/seed.json auth user failed to activate:
Extension "auth" failed to activate: User validation requires an endpoint context (APIError 403 validation_context_missing). Better Auth 1.7.6's internalAdapter.createUser requires an endpoint context whenever validateUserInfo is set, and seeding had none. databaseHooks ran with ctx undefined.

Fix

  • seedUsers runs inside Better Auth's runWithEndpointContext with a hermetic seed context: the auth context, no request (request, path undefined), empty headers. validateUserInfo gets {method: 'email-password', action: 'create-user'}.
  • A validator rejection (or throw) refuses the run: auth: seeded user <id> was refused by betterAuth.user.validateUserInfo (<code>...). A user.create.before / account.create.before hook returning false refuses naming the hook (previously it produced a misleading "generates its own ids" error).
  • Adds @better-auth/core 1.7.6 (same version as better-auth, already installed transitively) as a direct dependency for runWithEndpointContext; better-auth does not re-export it.
  • README (seeds and "Your own database") and CHANGELOG document the behavior. Also removes leftover merge-conflict markers from packages/auth/CHANGELOG.md on main.

Evidence

  • New test in packages/auth/test/owner-database.test.ts: failed before the fix with the error above; passes after. It asserts the validator's source and context, hook order (user.before, user.after, account.after) and context, sign-in of the seeded user, and both refusal messages.
  • npm run verify green locally.

Limitation: covered with Better Auth's memory adapter; the bundled SQLite path shares the same seedUsers code.

🤖 Generated with Claude Code

…c seed context (#1058)

Seeding called Better Auth's internalAdapter outside any endpoint context, so a
configured user.validateUserInfo refused every seed with "User validation
requires an endpoint context", and databaseHooks got no context. Seeding now
runs inside runWithEndpointContext with a synthetic context (no request, empty
headers). A validator rejection or a create.before hook returning false refuses
the run naming the user and the hook. Also removes stale merge markers from the
auth CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 30, 2026 15:39
@jimhoyd
jimhoyd merged commit 3bc54d4 into main Sep 30, 2026
26 checks passed
@jimhoyd
jimhoyd deleted the claude/auth-seed-validate-1058 branch September 30, 2026 15:55
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.

Auth seeds may fail when the owner configures Better Auth validateUserInfo (untested)

1 participant