[PR #6056] feat: support custom id field names #6411

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6056
Author: @Ridhim-RR
Created: 11/18/2025
Status: 🔄 Open

Base: canaryHead: custom-id-field-name


📝 Commits (3)

  • e1a376e feat:schema(session,user,account):add the custom id mapping
  • 27759ce feat(core): include id in user/session/account zod schemas
  • 12b720a chore: fix linting issues

📊 Changes

7 files changed (+126 additions, -5 deletions)

View changed files

packages/better-auth/src/adapters/adapter-factory/adapter-factory.id-field.test.ts (+93 -0)
📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+11 -2)
📝 packages/better-auth/src/db/get-tables.ts (+12 -0)
📝 packages/core/src/db/schema/account.ts (+1 -0)
📝 packages/core/src/db/schema/session.ts (+1 -0)
📝 packages/core/src/db/schema/user.ts (+1 -0)
📝 packages/core/src/types/init-options.ts (+7 -3)

📄 Description

Closes #5807

Summary

Adds support for configuring custom database column names for primary ID fields (e.g., user_id) while preserving that mapping at runtime. This ensures that generated IDs are correctly inserted into the configured columns, while callers still use the canonical id field.

Changes

  • Updated types and options in init-options.ts to support custom ID field names.
  • Added ID entries to the runtime schema generated by getAuthTables for user, session, and account schemas.
  • Modified Adapter Factory to preserve fieldName when injecting generated ID attributes, ensuring transformInput inserts generated IDs into the configured DB column.
  • Extended Zod schemas to include ID fields in userSchema, accountSchema, and sessionSchema.

Note: Support for custom Id columns is currently implemented only for the user, session and account tables.


Summary by cubic

Adds support for custom database column names for primary ID fields on user, session, and account tables. Generated IDs are written to the mapped columns, while callers continue to use the canonical id field.

  • New Features

    • Configure custom ID columns via options.user/session/account.fields.id.
    • Runtime schema includes id.fieldName and the adapter writes generated IDs to that column.
    • Added id to user, session, and account Zod schemas; tests verify mapping and adapter behavior.
  • Migration

    • If you use non-standard ID columns, set fields.id in your user/session/account options. No changes needed otherwise.

Written for commit 12b720acb5. 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/6056 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 11/18/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `custom-id-field-name` --- ### 📝 Commits (3) - [`e1a376e`](https://github.com/better-auth/better-auth/commit/e1a376eab119e6af3d704eea2b0b8aa995451257) feat:schema(session,user,account):add the custom id mapping - [`27759ce`](https://github.com/better-auth/better-auth/commit/27759ce7bb7ed01f4233e0a25a4f97c42c59dd5d) feat(core): include id in user/session/account zod schemas - [`12b720a`](https://github.com/better-auth/better-auth/commit/12b720acb5a5faf052b8fde8428dbf5d112851d1) chore: fix linting issues ### 📊 Changes **7 files changed** (+126 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/adapters/adapter-factory/adapter-factory.id-field.test.ts` (+93 -0) 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+11 -2) 📝 `packages/better-auth/src/db/get-tables.ts` (+12 -0) 📝 `packages/core/src/db/schema/account.ts` (+1 -0) 📝 `packages/core/src/db/schema/session.ts` (+1 -0) 📝 `packages/core/src/db/schema/user.ts` (+1 -0) 📝 `packages/core/src/types/init-options.ts` (+7 -3) </details> ### 📄 Description Closes #5807 ### Summary Adds support for configuring custom database column names for primary ID fields (e.g., user_id) while preserving that mapping at runtime. This ensures that generated IDs are correctly inserted into the configured columns, while callers still use the canonical id field. ### Changes - Updated types and options in init-options.ts to support custom ID field names. - Added ID entries to the runtime schema generated by getAuthTables for user, session, and account schemas. - Modified Adapter Factory to preserve fieldName when injecting generated ID attributes, ensuring transformInput inserts generated IDs into the configured DB column. - Extended Zod schemas to include ID fields in userSchema, accountSchema, and sessionSchema. **Note**: Support for custom Id columns is currently implemented only for the user, session and account tables. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds support for custom database column names for primary ID fields on user, session, and account tables. Generated IDs are written to the mapped columns, while callers continue to use the canonical id field. - **New Features** - Configure custom ID columns via options.user/session/account.fields.id. - Runtime schema includes id.fieldName and the adapter writes generated IDs to that column. - Added id to user, session, and account Zod schemas; tests verify mapping and adapter behavior. - **Migration** - If you use non-standard ID columns, set fields.id in your user/session/account options. No changes needed otherwise. <sup>Written for commit 12b720acb5a5faf052b8fde8428dbf5d112851d1. 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-03-13 12:58:17 -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#6411