[PR #5711] fix(adapters): respect default field names when serializing IDs for mongodb adapter #23072

Open
opened 2026-04-15 21:28:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5711
Author: @iamprompt
Created: 11/1/2025
Status: 🔄 Open

Base: mainHead: canary


📝 Commits (1)

  • 6689f9c fix(adapters/mongodb): respect default field names when serializing IDs

📊 Changes

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

View changed files

📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+14 -4)

📄 Description

This pull request updates the MongoDB adapter in the authentication package to improve how model and field names are resolved during ID serialization. The main change is that the adapter now supports a getDefaultFieldName function, which allows for more flexible and consistent mapping of field names.

Improvements to adapter customization:

  • The adapter factory now accepts a getDefaultFieldName parameter, enabling custom logic for resolving default field names.
  • The serializeID function uses getDefaultModelName and getDefaultFieldName to resolve model and field names, improving consistency and flexibility in ID handling.

Summary by cubic

Respect default field names during ID serialization in the MongoDB adapter to prevent incorrect ID mapping when models use custom field naming. The adapter now uses getDefaultFieldName alongside getDefaultModelName for consistent name resolution.

  • Bug Fixes
    • Adapter factory accepts getDefaultFieldName for default field resolution.
    • serializeID resolves model and field via getDefaultModelName and getDefaultFieldName before handling id/_id.

Written for commit 6689f9caba. Summary will update automatically on new commits.


🔄 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/5711 **Author:** [@iamprompt](https://github.com/iamprompt) **Created:** 11/1/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `canary` --- ### 📝 Commits (1) - [`6689f9c`](https://github.com/better-auth/better-auth/commit/6689f9caba02656249dd7e00c893bc9347f1c56a) fix(adapters/mongodb): respect default field names when serializing IDs ### 📊 Changes **1 file changed** (+14 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+14 -4) </details> ### 📄 Description This pull request updates the MongoDB adapter in the authentication package to improve how model and field names are resolved during ID serialization. The main change is that the adapter now supports a `getDefaultFieldName` function, which allows for more flexible and consistent mapping of field names. **Improvements to adapter customization:** * The adapter factory now accepts a `getDefaultFieldName` parameter, enabling custom logic for resolving default field names. * The `serializeID` function uses `getDefaultModelName` and `getDefaultFieldName` to resolve model and field names, improving consistency and flexibility in ID handling. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Respect default field names during ID serialization in the MongoDB adapter to prevent incorrect ID mapping when models use custom field naming. The adapter now uses getDefaultFieldName alongside getDefaultModelName for consistent name resolution. - **Bug Fixes** - Adapter factory accepts getDefaultFieldName for default field resolution. - serializeID resolves model and field via getDefaultModelName and getDefaultFieldName before handling id/_id. <sup>Written for commit 6689f9caba02656249dd7e00c893bc9347f1c56a. Summary will update automatically on new commits.</sup> <!-- 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-04-15 21:28:01 -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#23072