[PR #3160] [MERGED] Update to-auth-endpoints.ts #4678

Closed
opened 2026-03-13 11:55:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3160
Author: @Adityakk9031
Created: 6/24/2025
Status: Merged
Merged: 8/10/2025
Merged by: @Bekacru

Base: canaryHead: main


📝 Commits (10+)

  • 5fa7a56 Update to-auth-endpoints.ts
  • f08ea86 biome error
  • 7f36478 Merge branch 'better-auth:main' into main
  • 5cc2eaf first commit
  • e8379df Merge branch 'better-auth:main' into main
  • 375fff5 fix(org): use correct slug lookup when setting active org
  • e37e673 docs: adding reference to surrealdb adapter rewrite (#3754)
  • 2afdd69 chore(demo): replace isLoading using useTransition (#3775)
  • 669ce3e fix(reddit): refresh access token should use basic auth (#3753)
  • 1932d04 docs: unify component implementations for consistency (#3799)

📊 Changes

13 files changed (+309 additions, -292 deletions)

View changed files

📝 docs/content/docs/authentication/google.mdx (+2 -2)
📝 docs/content/docs/concepts/typescript.mdx (+0 -1)
📝 docs/content/docs/guides/optimizing-for-performance.mdx (+2 -2)
📝 docs/content/docs/integrations/hono.mdx (+3 -6)
📝 docs/content/docs/plugins/2fa.mdx (+1 -1)
📝 docs/content/docs/plugins/api-key.mdx (+2 -2)
📝 docs/content/docs/reference/options.mdx (+32 -1)
📝 examples/tanstack-example/app/lib/auth.ts (+4 -4)
📝 examples/tanstack-example/app/routes/__root.tsx (+213 -215)
examples/tanstack-example/biome.json (+0 -42)
📝 packages/better-auth/src/api/to-auth-endpoints.test.ts (+33 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+10 -3)
📝 packages/better-auth/src/cookies/cookies.test.ts (+7 -13)

📄 Description

This PR addresses issue #3126:
"Sign up additionalFields with array type items gets duplicated when using before hooks"

Root Cause:
The defu library is used to merge contexts, and it concatenates arrays by default, leading to duplication in fields like tags.

Fix:
Replaced defu with a custom defuReplaceArrays instance using createDefu, which replaces arrays instead of merging them.

Applied defuReplaceArrays in:

toAuthEndpoints (line 73)

runBeforeHooks (line 157)

🧪 Testing
Manual and unit testing confirmed that:

Arrays in ctx.body such as tags are no longer duplicated.

All other fields are still merged correctly.

📦 Commands used
bash
Copy
Edit
pnpm i
pnpm build
pnpm -F docs dev
Related Issue
Closes #3126


🔄 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/3160 **Author:** [@Adityakk9031](https://github.com/Adityakk9031) **Created:** 6/24/2025 **Status:** ✅ Merged **Merged:** 8/10/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `main` --- ### 📝 Commits (10+) - [`5fa7a56`](https://github.com/better-auth/better-auth/commit/5fa7a5676d4e5327335917ad0a64e6016dd244d2) Update to-auth-endpoints.ts - [`f08ea86`](https://github.com/better-auth/better-auth/commit/f08ea86fc662af604bb6f13868618e5cef0eb829) biome error - [`7f36478`](https://github.com/better-auth/better-auth/commit/7f36478df583aee473a983d3440f2406e6b38d49) Merge branch 'better-auth:main' into main - [`5cc2eaf`](https://github.com/better-auth/better-auth/commit/5cc2eafcd21859e09242d5afdc443ef49d08f752) first commit - [`e8379df`](https://github.com/better-auth/better-auth/commit/e8379dffb351d824bfd695f4eba80adbb75ca1a5) Merge branch 'better-auth:main' into main - [`375fff5`](https://github.com/better-auth/better-auth/commit/375fff5ac15b18b1e205c3cff6903a6ac609d2ec) fix(org): use correct slug lookup when setting active org - [`e37e673`](https://github.com/better-auth/better-auth/commit/e37e673e0417b2e8cbe0fc6b6f9b7932bc53b0b5) docs: adding reference to surrealdb adapter rewrite (#3754) - [`2afdd69`](https://github.com/better-auth/better-auth/commit/2afdd69e957564312fb1d3d2007ddcda07ccc3b5) chore(demo): replace isLoading using `useTransition` (#3775) - [`669ce3e`](https://github.com/better-auth/better-auth/commit/669ce3e6b737ce7c1a9ce982bf092f00d7373fbc) fix(reddit): refresh access token should use `basic` auth (#3753) - [`1932d04`](https://github.com/better-auth/better-auth/commit/1932d04c5a5be9180dab446e32b4ee1d5f788d24) docs: unify component implementations for consistency (#3799) ### 📊 Changes **13 files changed** (+309 additions, -292 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/authentication/google.mdx` (+2 -2) 📝 `docs/content/docs/concepts/typescript.mdx` (+0 -1) 📝 `docs/content/docs/guides/optimizing-for-performance.mdx` (+2 -2) 📝 `docs/content/docs/integrations/hono.mdx` (+3 -6) 📝 `docs/content/docs/plugins/2fa.mdx` (+1 -1) 📝 `docs/content/docs/plugins/api-key.mdx` (+2 -2) 📝 `docs/content/docs/reference/options.mdx` (+32 -1) 📝 `examples/tanstack-example/app/lib/auth.ts` (+4 -4) 📝 `examples/tanstack-example/app/routes/__root.tsx` (+213 -215) ➖ `examples/tanstack-example/biome.json` (+0 -42) 📝 `packages/better-auth/src/api/to-auth-endpoints.test.ts` (+33 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+10 -3) 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+7 -13) </details> ### 📄 Description This PR addresses issue [#3126](https://github.com/%3Cyour-org%3E/%3Crepo%3E/issues/3126): "Sign up additionalFields with array type items gets duplicated when using before hooks" ✅ Root Cause: The defu library is used to merge contexts, and it concatenates arrays by default, leading to duplication in fields like tags. ✅ Fix: Replaced defu with a custom defuReplaceArrays instance using createDefu, which replaces arrays instead of merging them. Applied defuReplaceArrays in: toAuthEndpoints (line 73) runBeforeHooks (line 157) 🧪 Testing Manual and unit testing confirmed that: Arrays in ctx.body such as tags are no longer duplicated. All other fields are still merged correctly. 📦 Commands used bash Copy Edit pnpm i pnpm build pnpm -F docs dev Related Issue Closes #3126 --- <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 11:55:23 -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#4678