Skip to content

Conversation

@zbeyens
Copy link
Member

@zbeyens zbeyens commented Oct 14, 2025

Summary

  • Sync adapter improvements from upstream fork
  • Add OR connector support in queries
  • Add sorting capabilities
  • Update to Better Auth 1.3.27 and @convex-dev/better-auth 0.9.5

Key Changes

  • ✅ OR connector support in findMany and count using asyncMap and unique
  • ✅ Sorting support in findMany when OR connectors are used
  • isRunMutationCtx option added to adapter
  • ✅ Made createSchema async for better module loading
  • ✅ Updated types from CleanedWhere to Where
  • ✅ Added remeda dependency for sorting operations
  • ✅ Fixed error messages and return value consistency

Breaking Change

⚠️ The onUpdate trigger parameters have been swapped:

  • Before: onUpdate(ctx, oldDoc, newDoc)
  • After: onUpdate(ctx, newDoc, oldDoc)

This aligns with the upstream design where the new doc is used more frequently.

Test plan

  • Type checks pass
  • All dependencies installed correctly
  • Both httpAdapter and dbAdapter updated with fork improvements

🤖 Generated with Claude Code

- Add OR connector support in findMany and count queries
- Add sorting support in findMany with OR connectors
- Add isRunMutationCtx option to adapter
- Make createSchema async
- Update types from CleanedWhere to Where
- Fix error messages and return values
- Add remeda dependency for sorting operations
- Swap old and new doc params in onUpdate trigger (BREAKING)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Oct 14, 2025

🦋 Changeset detected

Latest commit: fcbc004

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
better-auth-convex Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@zbeyens zbeyens merged commit e030ef6 into main Oct 14, 2025
1 check passed
@zbeyens zbeyens deleted the feat/sync-upstream-fork branch October 14, 2025 07:16
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment on lines +300 to +304
async ({ paginationOpts }) => {
return await ctx.runQuery(authFunctions.findMany, {
...data,
paginationOpts,
where: parseWhere([w]),

Choose a reason for hiding this comment

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

P1 Badge Handle OR predicates without dropping AND filters

When any OR connector appears, the adapter executes each clause separately and replaces the whole where array with the single OR condition (where: parseWhere([w])). This discards any non‑OR predicates that were present in the original query, so mixed queries such as (email = X OR username = Y) AND isActive = true will return documents that satisfy the OR condition even if isActive is false. The same pattern exists in both httpAdapter and dbAdapter for findMany and count, producing incorrect results and counts.

Useful? React with 👍 / 👎.

{ limit: data.limit }
)
);
const docs = unique(results.flatMap((r) => r.docs));

Choose a reason for hiding this comment

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

P1 Badge Deduplicate OR results by document id

After gathering the per‑clause pages, results are deduped with unique(results.flatMap(...)), which only compares object references. A document returned from two OR subqueries will be two different object instances and will therefore survive unique, so callers receive duplicates and count inflates the total. Deduplication needs to key off a stable identifier (e.g. _id) or use uniqueBy rather than the reference-based unique. The same issue affects both adapters’ count and findMany implementations.

Useful? React with 👍 / 👎.

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.

2 participants