[PR #3902] [CLOSED] fix(api): replace defu array concatenation with override in hook context merges #5073

Closed
opened 2026-03-13 12:09:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3902
Author: @Kinfe123
Created: 8/10/2025
Status: Closed

Base: canaryHead: fix/array-override-in-before-hooks


📝 Commits (2)

  • 9b206d2 fix(api): replace defu array concatenation with override in hook context merges
  • 3ecd62e lint

📊 Changes

2 files changed (+52 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/api/to-auth-endpoints.test.ts (+33 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+19 -3)

📄 Description

This pr fixes on the Use a custom defu merger (createDefu) that replaces arrays instead of concatenating
when merging contexts from before hooks into internalContext/modifiedContext.
Prevents duplication for array additionalFields (e.g., user.tags).

Closes #3126


Summary by cubic

Updated context merging in before hooks to replace arrays instead of concatenating them, preventing duplicate values in fields like user.tags.

  • Bug Fixes
  • Arrays in hook contexts now override existing arrays instead of merging, matching expected behavior and fixing duplication issues.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3902 **Author:** [@Kinfe123](https://github.com/Kinfe123) **Created:** 8/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/array-override-in-before-hooks` --- ### 📝 Commits (2) - [`9b206d2`](https://github.com/better-auth/better-auth/commit/9b206d2c965e275db0c760a5714474eac21d3da1) fix(api): replace defu array concatenation with override in hook context merges - [`3ecd62e`](https://github.com/better-auth/better-auth/commit/3ecd62ec20526372c6ad752a0661f6801a07aa84) lint ### 📊 Changes **2 files changed** (+52 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/to-auth-endpoints.test.ts` (+33 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+19 -3) </details> ### 📄 Description This pr fixes on the Use a custom defu merger (createDefu) that replaces arrays instead of concatenating when merging contexts from before hooks into internalContext/modifiedContext. Prevents duplication for array additionalFields (e.g., user.tags). Closes #3126 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Updated context merging in before hooks to replace arrays instead of concatenating them, preventing duplicate values in fields like user.tags. - **Bug Fixes** - Arrays in hook contexts now override existing arrays instead of merging, matching expected behavior and fixing duplication issues. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:09:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5073