fix(oauth-provider): fix dist declaration type errors#8701
Merged
himself65 merged 1 commit intobetter-auth:canaryfrom Mar 20, 2026
Merged
Conversation
The monorepo uses `customConditions: ["dev-source"]` in tsconfig.base.json, which resolves workspace imports to source `.ts` files during `tsc --build`. This means the root `pnpm typecheck` never validates the emitted `.d.mts` declarations from `tsdown`. When consumers import `@better-auth/oauth-provider` via the published dist output (or when typechecking from within the package), 8 type errors surface because the emitted declarations lose type narrowing that the source code relies on. Fixes: - client-resource.ts: narrow `baseURL` to `string | undefined` since `DynamicBaseURLConfig` cannot be used as a static issuer/audience - consent.ts: cast context to `Record<string, unknown>` for the dynamically-added `postLogin` property - register.ts: default `redirect_uris` to `[]` instead of `undefined` - utils/index.ts: drop invalid second string arg from BetterAuthError (constructor signature is `(message, options?)` not `(code, message)`)
|
@gustavovalverde is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes TypeScript declaration (.d.mts) type errors in the published oauth-provider package that don’t show up in monorepo development due to dev-source conditional exports, improving compatibility for external consumers importing from dist.
Changes:
- Fix invalid
BetterAuthErrorconstructor usage ingetJwtPlugin. - Ensure
redirect_urisis always astring[]inschemaToOAuthoutput. - Avoid relying on non-string
baseURLconfigs by narrowing tostring | undefinedin the resource client. - Avoid assigning an undeclared property on
AuthContextby casting before settingpostLogin.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/oauth-provider/src/utils/index.ts | Removes invalid second BetterAuthError argument to fix emitted declaration typing. |
| packages/oauth-provider/src/register.ts | Defaults redirect_uris to [] to satisfy required array type in emitted declarations. |
| packages/oauth-provider/src/consent.ts | Casts context before setting postLogin to avoid dist type errors. |
| packages/oauth-provider/src/client-resource.ts | Narrows auth.options.baseURL to a static string before using as issuer/audience. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
himself65
approved these changes
Mar 20, 2026
Merged
via the queue into
better-auth:canary
with commit Mar 20, 2026
c41fa04
25 of 28 checks passed
gustavovalverde
added a commit
to gustavovalverde/better-auth
that referenced
this pull request
Mar 20, 2026
Add `typecheck:dist` that validates package source against workspace dependencies' dist declarations instead of source (disables the `dev-source` custom condition). This catches type errors that `pnpm typecheck` misses due to `customConditions: ["dev-source"]` resolving all imports to source `.ts` files. Excludes `better-auth`, `core`, and `electron` source from the check because their `declare module` augmentations conflict with their own dist augmentations when both are visible to the compiler. Context: see better-auth#8701 for the full explanation of the `dev-source` masking issue.
himself65
pushed a commit
that referenced
this pull request
Mar 20, 2026
Merged
himself65
pushed a commit
that referenced
this pull request
Mar 20, 2026
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.
Summary
The
oauth-providerpackage has 8 type errors in its emitted.d.mtsdeclarations that are invisible during development but break external consumers. This PR fixes them and adds CI validation to prevent regressions.Why these errors are hidden
The monorepo uses
customConditions: ["dev-source"]intsconfig.base.json, which resolves workspace imports to source.tsfiles instead of builtdist/output:Each package exports a
dev-sourcecondition:So
pnpm typecheck(roottsc --build) resolves all cross-package imports to source — types are always consistent. But the published dist declarations have real type issues.tsc --build.tsvia dev-sourcetsc --noEmit.d.mtsfilesCommit 1: Fix the 8 type errors
client-resource.ts(5 errors) —auth?.options.baseURLtyped asBaseURLConfig(includesDynamicBaseURLConfig) in dist. Fix: narrow tostring | undefinedwith atypeofcheck.consent.ts(1 error) —ctx.context.postLogindoesn't exist on distAuthContext(dynamically added at runtime). Fix: cast toRecord<string, unknown>.register.ts(1 error) —redirect_uristyped asstring[] | undefinedin dist, assigned tostring[]. Fix: default to[].utils/index.ts(1 error) —BetterAuthError("jwt_config", "jwt plugin not found")— second arg is a string but constructor expects{ cause?: unknown }. Silently ignored at runtime. Fix: drop invalid second arg.Commit 2: Add dist declaration CI check
Adds
tsconfig.dist-check.jsonat the repo root that:customConditions(disablesdev-sourceresolution)composite: false+noEmit: truebetter-auth,core, andelectron(top-level packages that can't be dist-checked against themselves due to module augmentation conflicts)Available locally via
pnpm typecheck:distand runs in CI after the build step.How to reproduce
Test plan
pnpm typecheck(root, dev-source) still passespnpm lintpassespnpm typecheck:dist— 0 errors (was 8)