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

Open
opened 2026-04-13 09:27:53 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5711

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5711 **State:** open **Merged:** No --- 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:27: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#14418