[PR #4924] [MERGED] fix: handle symbols in proxy get trap to prevent TypeError #5663

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4924
Author: @zbeyens
Created: 9/26/2025
Status: Merged
Merged: 10/2/2025
Merged by: @himself65

Base: canaryHead: fix/segment-replace-error


📝 Commits (3)

  • 0e44fbc fix: handle symbols in proxy get trap to prevent TypeError
  • 2d5d452 fix: proxy.ts
  • 1856b91 Merge branch 'canary' into fix/segment-replace-error

📊 Changes

1 file changed (+4 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/client/proxy.ts (+4 -1)

📄 Description

Description

Fixes TypeError: segment.replace is not a function that occurs when using Better Auth client in Next.js/React applications.

The Problem

When using the Better Auth client proxy in Next.js applications, the following error occurs:
TypeError: segment.replace is not a function at AuthProvider (../../../src/react/client.tsx:127:12)

This happens because JavaScript Proxies receive both string and symbol property keys in their get trap.

The proxy's get trap was typed to only accept strings, but when symbols were accessed, they would be added to the path array and cause .replace() to fail since symbols don't have string methods.

The Solution

  1. Correctly type the prop parameter: Changed from string to string | symbol
  2. Handle symbols explicitly: Added an early return for symbol properties, returning undefined
  3. Prevent symbols from entering the path array: This ensures only strings are processed when building the route path

Changes Made

  • Updated the Proxy get trap type signature in packages/better-auth/src/client/proxy.ts
  • Added symbol type checking to return early when symbols are accessed

🔄 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/4924 **Author:** [@zbeyens](https://github.com/zbeyens) **Created:** 9/26/2025 **Status:** ✅ Merged **Merged:** 10/2/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/segment-replace-error` --- ### 📝 Commits (3) - [`0e44fbc`](https://github.com/better-auth/better-auth/commit/0e44fbc1f0e1447469003aa7f429f4ec9e9eecd0) fix: handle symbols in proxy get trap to prevent TypeError - [`2d5d452`](https://github.com/better-auth/better-auth/commit/2d5d4528c961754637ec2fb2c660be1f0f856157) fix: proxy.ts - [`1856b91`](https://github.com/better-auth/better-auth/commit/1856b91b784f2ceb4567331c1582aace175da8dd) Merge branch 'canary' into fix/segment-replace-error ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/client/proxy.ts` (+4 -1) </details> ### 📄 Description ## Description Fixes TypeError: `segment.replace is not a function` that occurs when using Better Auth client in Next.js/React applications. ## The Problem When using the Better Auth client proxy in Next.js applications, the following error occurs: `TypeError: segment.replace is not a function at AuthProvider (../../../src/react/client.tsx:127:12)` This happens because JavaScript Proxies receive both `string` and `symbol` property keys in their `get` trap. The proxy's `get` trap was typed to only accept strings, but when symbols were accessed, they would be added to the path array and cause `.replace()` to fail since symbols don't have string methods. ## The Solution 1. **Correctly type the prop parameter**: Changed from `string` to `string | symbol` 2. **Handle symbols explicitly**: Added an early return for symbol properties, returning `undefined` 3. **Prevent symbols from entering the path array**: This ensures only strings are processed when building the route path ## Changes Made - Updated the Proxy get trap type signature in `packages/better-auth/src/client/proxy.ts` - Added symbol type checking to return early when symbols are accessed --- <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:30:58 -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#5663