Skip to content

fix(client): use direct imports to fix bundler re-export type resolution#8261

Merged
himself65 merged 3 commits intocanaryfrom
himself65/2026/03/02/infer-client
Mar 1, 2026
Merged

fix(client): use direct imports to fix bundler re-export type resolution#8261
himself65 merged 3 commits intocanaryfrom
himself65/2026/03/02/infer-client

Conversation

@himself65
Copy link
Copy Markdown
Contributor

Fixes: #8258

@himself65 himself65 requested a review from Bekacru as a code owner March 1, 2026 16:22
Copilot AI review requested due to automatic review settings March 1, 2026 16:22
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
better-auth-demo Ignored Ignored Mar 1, 2026 4:46pm
better-auth-docs Skipped Skipped Mar 1, 2026 4:46pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 1, 2026

Open in StackBlitz

@better-auth/api-key

npm i https://pkg.pr.new/@better-auth/api-key@8261

better-auth

npm i https://pkg.pr.new/better-auth@8261

auth

npm i https://pkg.pr.new/auth@8261

@better-auth/core

npm i https://pkg.pr.new/@better-auth/core@8261

@better-auth/drizzle-adapter

npm i https://pkg.pr.new/@better-auth/drizzle-adapter@8261

@better-auth/electron

npm i https://pkg.pr.new/@better-auth/electron@8261

@better-auth/expo

npm i https://pkg.pr.new/@better-auth/expo@8261

@better-auth/i18n

npm i https://pkg.pr.new/@better-auth/i18n@8261

@better-auth/kysely-adapter

npm i https://pkg.pr.new/@better-auth/kysely-adapter@8261

@better-auth/memory-adapter

npm i https://pkg.pr.new/@better-auth/memory-adapter@8261

@better-auth/mongo-adapter

npm i https://pkg.pr.new/@better-auth/mongo-adapter@8261

@better-auth/oauth-provider

npm i https://pkg.pr.new/@better-auth/oauth-provider@8261

@better-auth/passkey

npm i https://pkg.pr.new/@better-auth/passkey@8261

@better-auth/prisma-adapter

npm i https://pkg.pr.new/@better-auth/prisma-adapter@8261

@better-auth/redis-storage

npm i https://pkg.pr.new/@better-auth/redis-storage@8261

@better-auth/scim

npm i https://pkg.pr.new/@better-auth/scim@8261

@better-auth/sso

npm i https://pkg.pr.new/@better-auth/sso@8261

@better-auth/stripe

npm i https://pkg.pr.new/@better-auth/stripe@8261

@better-auth/telemetry

npm i https://pkg.pr.new/@better-auth/telemetry@8261

@better-auth/test-utils

npm i https://pkg.pr.new/@better-auth/test-utils@8261

commit: c41d854

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes broken client typings (notably updateUser and updateSession) by refining how request context types are inferred for client endpoints, avoiding cases where InputContext inference collapses to any.

Changes:

  • Introduces metadata-based body inference (metadata.$Infer.body) for endpoint call signatures to prevent any leakage.
  • Adds InferEndpointCtx to choose between metadata-inferred body types and the existing InferCtx fallback.
  • Ensures /update-user keeps a dedicated, client-options-based input type (InferUserUpdateCtx) regardless of required/optional-arg detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +114 to +170
@@ -138,25 +149,26 @@ export type InferRoute<API, COpts extends BetterAuthClientOptions> =
C["params"]
>,
>(
...data: HasRequiredKeys<
InferCtx<C, FetchOptions>
> extends true
...data: T["path"] extends `/update-user`
? [
Prettify<
T["path"] extends `/sign-up/email`
? InferSignUpEmailCtx<COpts, FetchOptions>
: InferCtx<C, FetchOptions>
>,
FetchOptions?,
]
: [
Prettify<
T["path"] extends `/update-user`
? InferUserUpdateCtx<COpts, FetchOptions>
: InferCtx<C, FetchOptions>
>?,
Prettify<InferUserUpdateCtx<COpts, FetchOptions>>?,
FetchOptions?,
]
: HasRequiredKeys<
InferEndpointCtx<T, C, FetchOptions>
> extends true
? [
Prettify<
T["path"] extends `/sign-up/email`
? InferSignUpEmailCtx<COpts, FetchOptions>
: InferEndpointCtx<T, C, FetchOptions>
>,
FetchOptions?,
]
: [
Prettify<InferEndpointCtx<T, C, FetchOptions>>?,
FetchOptions?,
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new endpoint-context inference now depends on metadata.$Infer.body (via InferEndpointCtx) to avoid any leaking from InputContext. There are existing type-level tests in packages/better-auth/src/client/client.test.ts, but none that assert the updateUser / updateSession call signatures; adding a couple expectTypeOf(client.updateUser) / expectTypeOf(client.updateSession) assertions would help prevent regressions of issue #8258.

Copilot uses AI. Check for mistakes.
@himself65 himself65 force-pushed the himself65/2026/03/02/infer-client branch from 6166531 to e3dceb4 Compare March 1, 2026 16:26
@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 1, 2026 16:26 Inactive
@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 1, 2026 16:39 Inactive
The bundler (tsdown/rolldown) doesn't include re-exported types from
external packages in `declare namespace` blocks. Importing through
local barrel re-exports (e.g., `../db`, `../..`) caused types like
`InferDBFieldsFromPluginsInput` and `GenericEndpointContext` to be
unresolvable in the build output, collapsing to `any`.

- Revert path-to-object.ts workarounds (no longer needed)
- Fix jwt/types.ts: import GenericEndpointContext from @better-auth/core
@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 1, 2026 16:46 Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/better-auth/src/client/path-to-object.ts">

<violation number="1" location="packages/better-auth/src/client/path-to-object.ts:103">
P1: The new `IsAny<C["body"]>` branch omits the optional-query case, so endpoints with `body: any` and `query: Record | undefined` lose their `query` input type.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}
: C["query"] extends Record<string, any>
IsAny<C["body"]> extends true
? C["query"] extends Record<string, any>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The new IsAny<C["body"]> branch omits the optional-query case, so endpoints with body: any and query: Record | undefined lose their query input type.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/better-auth/src/client/path-to-object.ts, line 103:

<comment>The new `IsAny<C["body"]>` branch omits the optional-query case, so endpoints with `body: any` and `query: Record | undefined` lose their `query` input type.</comment>

<file context>
@@ -89,35 +89,61 @@ export type InferUserUpdateCtx<
-			}
-		: C["query"] extends Record<string, any>
+	IsAny<C["body"]> extends true
+		? C["query"] extends Record<string, any>
 			? {
 					query: C["query"];
</file context>
Fix with Cubic

@himself65 himself65 changed the title fix(client): refine endpoint context inference logic fix(client): use direct imports to fix bundler re-export type resolution Mar 1, 2026
@himself65 himself65 enabled auto-merge March 1, 2026 16:47
@himself65 himself65 added this pull request to the merge queue Mar 1, 2026
Merged via the queue into canary with commit ed7d6c3 Mar 1, 2026
25 checks passed
@himself65 himself65 mentioned this pull request Mar 2, 2026
@better-auth better-auth locked as resolved and limited conversation to collaborators Mar 31, 2026
@bytaesu bytaesu added the locked Locked conversations after being closed for 7 days label Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked Locked conversations after being closed for 7 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updateUser and updateSession typings broken for client

3 participants