fix(schema): skip generation when the auth config fails to load - #422
Open
jd-solanki wants to merge 1 commit into
Open
fix(schema): skip generation when the auth config fails to load#422jd-solanki wants to merge 1 commit into
jd-solanki wants to merge 1 commit into
Conversation
`loadUserAuthConfig` swallowed a load failure in dev and returned `{}`,
indistinguishable from an empty-but-valid config. `setupBetterAuthSchema`
then generated a schema from those empty options and overwrote
`.nuxt/better-auth/schema.<dialect>.ts` with core tables only, dropping
every `user.additionalFields` entry and every plugin-contributed column.
The next `drizzle-kit generate` read that file and emitted a migration
dropping those columns. `nuxt prepare` throws on the same failure, so only
the dev server was affected — and it kept serving with no sign that the
schema on disk was now wrong.
`loadUserAuthConfig` now returns `null` on a swallowed failure, from both
the thrown-error `catch` and the "does not export default" branch, so
callers can tell failure from an empty config. `setupBetterAuthSchema`
returns before touching the filesystem, leaving the previously generated
file alone, and the dev-mode error says so rather than the old, now
untrue "Schema may be incomplete".
Registration of the `hub:db:schema:extend` hook moves above the bail: the
whole point is to keep the good file on disk, so NuxtHub must still resolve
it on a run that generates nothing. `resolveHubSchemaPath` is a plain
filesystem lookup and does not care which run produced the file.
Behaviour on a successful load is unchanged, and dev still does not throw.
Closes nuxt-modules#419
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mn1xnJsSCpdbPEEZAFL1Si
Contributor
|
@jd-solanki is attempting to deploy a commit to the maximogarciamartinez's projects Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
jd-solanki
marked this pull request as ready for review
August 28, 2026 20:00
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.
Why
Reported in #419. When
server/auth.config.tsfails to load,nuxt devlogs an error and thengenerates the Drizzle schema anyway, from an empty options object. The correct
.nuxt/better-auth/schema.<dialect>.tsalready on disk is replaced by one carrying core tablesonly, losing every
user.additionalFieldsentry and every plugin-contributed column.drizzle-kit generatereads that file next, so the migration it produces drops those columns.The dev server keeps serving normally and the success log line reads the same as a healthy run,
so nothing signals that the schema is now wrong. There is a runnable reproduction on the issue.
Notes
loadUserAuthConfig's return type gains| null. Despite theexport, it is unreachable fromany consumer:
build.config.tsbuilds only the module entry, theexportsmap exposes just.,./composablesand./config, andsrc/module.tsdoes not re-export it. The only call site isin
src/module/schema.ts. A non-enumerable marker on the existing{}would have been strictlyadditive, but
nulllets the type checker find the call sites, which seemed the better trade fora bug fix. Say the word if you would rather have the additive version.
The
hub:db:schema:extendregistration moved above thetrydeliberately. Left where it was, thenew early return skips it, and NuxtHub ends up with no auth schema path at all: the correct file
preserved on disk but orphaned from its only consumer.
setupBetterAuthSchemaruns once at modulesetup, so there is no second chance. There is a regression test for this.
better-auth:config:extendno longer fires when the load failed, sinceloadAuthOptionsreturnsbefore it. Nothing consumes its result on that path, but it is a visible change if a module relies
on the hook firing on every setup. Moving the bail below the hook is a one-line change if you
prefer that.
nuxt devstill does not throw the waynuxt preparedoes. That is deliberate. It is a behaviourchange that did not belong in a bug fix, and the reported problem is fixed without it.
Unrelated and untouched:
setupBetterAuthSchema'scatchends withif (isProduction) throw errorfollowed by an unconditional
throw error, so the production check is dead. Worth its own issue.Closes #419