Skip to content

fix cross-domain client plugin types - #391

Merged
erquhart merged 1 commit into
convex:mainfrom
zbeyens:codex/fix-cross-domain-client-types
Jun 17, 2026
Merged

erquhart merged 1 commit into
convex:mainfrom
zbeyens:codex/fix-cross-domain-client-types

Conversation

@zbeyens

@zbeyens zbeyens commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🐛 Fixes #195

🟢 95-100% confidence

Phase 🧪 Tests 🌐 Browser
Reproduced 🔴 /tmp/convex-ba-repro-j7CbNK npm run typecheck failed before patch with better-auth@1.6.18: crossDomainClient() rejected as BetterAuthClientPlugin; getCookie missing ➖ N/A
Verified 🟢 npm run build; npm run test; npm run lint; npm run typecheck; repacked tarball repro passed against better-auth@1.6.18 ➖ N/A

✅ Outcome

crossDomainClient() now composes with current Better Auth 1.6.x client plugins and keeps inferred actions such as getCookie.

⚠️ Caveat

This does not fix Better Auth's broader inferred-client type explosion/OOM class. It fixes the @convex-dev/better-auth compatibility bug that made the supported peer range lie.

🏗️ Design

The fix is a type-boundary repair on crossDomainClient(): use Better Auth's current client plugin contract, keep the current getActions parameter shape, and preserve the concrete cross-domain server plugin/actions inference. Runtime object shape is unchanged.

🧪 Verified

  • npm run build
  • npx vitest run --typecheck src/plugins/cross-domain/client.types.test.ts src/plugins/cross-domain/client.test.ts
  • npm run test
  • npm run lint
  • npm run typecheck
  • /tmp/convex-ba-repro-j7CbNK npm run typecheck with repacked package + better-auth@1.6.18
  • autoreview --mode local: clean, no accepted/actionable findings

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@zbeyens is attempting to deploy a commit to the Convex Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The crossDomainClient plugin in client.ts is updated to fix a TypeScript incompatibility with better-auth@1.4.7. Imports of BetterAuthClientPlugin and ClientStore are moved from better-auth to better-auth/client. Two new internal types are introduced: CrossDomainActions (describing the three plugin actions: getCookie, notifySessionUpdate, getSession) and CrossDomainClientPlugin (a narrowed plugin type binding $InferServerPlugin to ReturnType<typeof crossDomain> and constraining getActions to return CrossDomainActions). The factory function gains an explicit : CrossDomainClientPlugin return type annotation, and the trailing satisfies BetterAuthClientPlugin constraint is removed. Test helpers in client.test.ts are adjusted to pass a third undefined argument to plugin.getActions and add a non-null assertion on plugin.fetchPlugins. A new client.types.test.ts file adds a type-level test asserting that getCookie is inferred as () => string when composing crossDomainClient in a React auth client.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing type issues with the cross-domain client plugin.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the TypeScript type compatibility issue and the fix applied.
Linked Issues check ✅ Passed The PR addresses issue #195 by fixing the BetterAuthClientPlugin type compatibility with a type-boundary repair on crossDomainClient() to align with Better Auth's current client plugin contract while preserving concrete cross-domain actions inference.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the crossDomainClient() type compatibility issue; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/plugins/cross-domain/client.ts (1)

93-93: 💤 Low value

Consider explicitly accepting all parameters for clarity.

The implementation accepts two parameters (_, $store), but the type signature (via Parameters<NonNullable<BetterAuthClientPlugin["getActions"]>>) and test calls (line 141, 157 in the test file) suggest Better Auth expects three parameters. While TypeScript allows ignoring trailing parameters, explicitly accepting all three would improve clarity:

-    getActions(_, $store) {
+    getActions(_, $store, _options) {

This makes the signature more explicit and aligns with the test calls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/cross-domain/client.ts` at line 93, The getActions method in the
client.ts file currently accepts only two parameters (_, $store) but the type
signature and test calls indicate it should accept three parameters. Update the
getActions method signature to explicitly accept all three parameters instead of
omitting the trailing parameter, which will improve code clarity and ensure the
implementation aligns with the expected type signature from
BetterAuthClientPlugin and the test calls shown at lines 141 and 157.
src/plugins/cross-domain/client.test.ts (1)

146-146: 💤 Low value

Non-null assertions on fetchPlugins access.

The non-null assertions (plugin.fetchPlugins!) suggest that fetchPlugins is optional in the BetterAuthClientPlugin type. While the crossDomainClient implementation always provides fetchPlugins, this assertion pattern could mask issues if:

  1. The plugin implementation changes in the future
  2. These helpers are used with other plugins

Consider adding a runtime check if the helpers might be used with other plugins:

if (!plugin.fetchPlugins) {
  throw new Error("Plugin does not provide fetchPlugins");
}
return plugin.fetchPlugins[0].hooks!.onSuccess!;

For test-only code specifically testing crossDomainClient, the current approach is acceptable.

Also applies to: 158-158

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/cross-domain/client.test.ts` at line 146, The non-null assertions
on plugin.fetchPlugins access are acceptable in this test file since the code is
specifically testing the crossDomainClient implementation which always provides
fetchPlugins. Since this is test-only code, no change is required. However, if
similar helper patterns were to be extracted and used in production code with
other plugin types, consider adding a runtime check to verify that fetchPlugins
exists before accessing it, as suggested in the comment example.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/plugins/cross-domain/client.types.test.ts`:
- Around line 1-5: Remove the `adminClient` import from the import statement in
the test file since it is not exported from the local repository's client
plugins module at `src/client/plugins/index.ts`. The import from
"better-auth/client/plugins" is unresolvable in this context and the symbol is
not being used in the test, so simply delete this import while keeping the other
imports intact (createAuthClient, expectTypeOf, it, convexClient, and
crossDomainClient).

---

Nitpick comments:
In `@src/plugins/cross-domain/client.test.ts`:
- Line 146: The non-null assertions on plugin.fetchPlugins access are acceptable
in this test file since the code is specifically testing the crossDomainClient
implementation which always provides fetchPlugins. Since this is test-only code,
no change is required. However, if similar helper patterns were to be extracted
and used in production code with other plugin types, consider adding a runtime
check to verify that fetchPlugins exists before accessing it, as suggested in
the comment example.

In `@src/plugins/cross-domain/client.ts`:
- Line 93: The getActions method in the client.ts file currently accepts only
two parameters (_, $store) but the type signature and test calls indicate it
should accept three parameters. Update the getActions method signature to
explicitly accept all three parameters instead of omitting the trailing
parameter, which will improve code clarity and ensure the implementation aligns
with the expected type signature from BetterAuthClientPlugin and the test calls
shown at lines 141 and 157.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: get-convex/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f6342caf-2e33-4913-98e0-c693e0ec68a4

📥 Commits

Reviewing files that changed from the base of the PR and between c8df679 and 318646f.

📒 Files selected for processing (3)
  • src/plugins/cross-domain/client.test.ts
  • src/plugins/cross-domain/client.ts
  • src/plugins/cross-domain/client.types.test.ts

Comment thread src/plugins/cross-domain/client.types.test.ts
@zbeyens zbeyens closed this Jun 15, 2026
@erquhart erquhart reopened this Jun 17, 2026
@erquhart

Copy link
Copy Markdown
Member

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/better-auth@391

commit: 318646f

@erquhart
erquhart merged commit e18fdf4 into convex:main Jun 17, 2026
3 of 4 checks passed
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.

crossDomainClient() type incompatibility with better-auth@1.4.7

2 participants