[PR #5330] feat: support custom field attributes in plugin schemas #31534

Open
opened 2026-04-17 22:25:54 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5330
Author: @ping-maxwell
Created: 10/15/2025
Status: 🔄 Open

Base: nextHead: feat/custom-field-attr-for-plugin-schemas


📝 Commits (10+)

  • b12073d feat: support custom field attributes in plugin schemas
  • 11922bf fix: support nested merge
  • d6e6c08 chore: lint
  • e0ab60a Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas
  • e17a5ec Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas
  • 8503c2b Add missing email validation (#5593)
  • 31892f6 Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas
  • 627013b Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas
  • 9936e75 Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas
  • 8ec9e9a chore: lint

📊 Changes

2 files changed (+28 additions, -14 deletions)

View changed files

📝 packages/better-auth/src/db/schema.ts (+23 -11)
📝 packages/better-auth/src/types/plugins.ts (+5 -3)

📄 Description

In the auth config, you can define a user/session/account/etc schema to customize the field attributes in a given table.

Right now with plugin schemas, you can only customize the field name. With this PR, will allow support for customizing any field attribute of the field, not just field name.

For example, in the Username plugin, you can't enforce the username to be required. With this PR you can do so:

const auth = betterAuth({
    plugins: [
        username({
            schema: {
                user: {
                    fields: {
                        username: {
                            required: true
                        }
                    }
                }
            }
        })
    ]
})

Please merge the following PR after this is merged:
https://github.com/better-auth/better-auth/pull/5323


Summary by cubic

Enable plugin schemas to override any DB field attributes, not just rename fields. This lets plugins enforce constraints (e.g., required username) via auth config while staying backward compatible.

  • New Features

    • Plugin schema fields now accept string (rename) or Partial (attribute overrides).
    • mergeSchema merges attribute overrides and does a nested merge for transform/validator input/output, preserving existing values when not provided.
  • Migration

    • No breaking changes. Existing string-based field renames continue to work.

Written for commit c942d46f9a. 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/5330 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/15/2025 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/custom-field-attr-for-plugin-schemas` --- ### 📝 Commits (10+) - [`b12073d`](https://github.com/better-auth/better-auth/commit/b12073dbddd6fe660cca6aba580f0ed7027e5d79) feat: support custom field attributes in plugin schemas - [`11922bf`](https://github.com/better-auth/better-auth/commit/11922bf6134ba569ee0f7e16dd861c6511935eca) fix: support nested merge - [`d6e6c08`](https://github.com/better-auth/better-auth/commit/d6e6c08b0e8bdbd0c5f850539af879af175934f6) chore: lint - [`e0ab60a`](https://github.com/better-auth/better-auth/commit/e0ab60a7ddcce3a37be1e15e762aeb31350f3cf4) Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas - [`e17a5ec`](https://github.com/better-auth/better-auth/commit/e17a5ec6967a878a5cd925d3662a9928b9095bb0) Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas - [`8503c2b`](https://github.com/better-auth/better-auth/commit/8503c2b79f8fc9824006823f627acf7e8ad46d25) Add missing email validation (#5593) - [`31892f6`](https://github.com/better-auth/better-auth/commit/31892f6361950696ffa5a3e442405e7b7568e8b6) Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas - [`627013b`](https://github.com/better-auth/better-auth/commit/627013be92c5cc0a5c9fc8c718e12641fd10ed37) Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas - [`9936e75`](https://github.com/better-auth/better-auth/commit/9936e7579d4f5e08bb295fda97f8ba7272438c0d) Merge branch 'canary' into feat/custom-field-attr-for-plugin-schemas - [`8ec9e9a`](https://github.com/better-auth/better-auth/commit/8ec9e9abda9f596642e3e163deb58691ebff4961) chore: lint ### 📊 Changes **2 files changed** (+28 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/schema.ts` (+23 -11) 📝 `packages/better-auth/src/types/plugins.ts` (+5 -3) </details> ### 📄 Description In the auth config, you can define a user/session/account/etc schema to customize the field attributes in a given table. Right now with plugin schemas, you can only customize the field name. With this PR, will allow support for customizing any field attribute of the field, not just field name. For example, in the Username plugin, you can't enforce the `username` to be required. With this PR you can do so: ```ts const auth = betterAuth({ plugins: [ username({ schema: { user: { fields: { username: { required: true } } } } }) ] }) ``` Please merge the following PR after this is merged: https://github.com/better-auth/better-auth/pull/5323 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Enable plugin schemas to override any DB field attributes, not just rename fields. This lets plugins enforce constraints (e.g., required username) via auth config while staying backward compatible. - **New Features** - Plugin schema fields now accept string (rename) or Partial<DBFieldAttribute> (attribute overrides). - mergeSchema merges attribute overrides and does a nested merge for transform/validator input/output, preserving existing values when not provided. - **Migration** - No breaking changes. Existing string-based field renames continue to work. <sup>Written for commit c942d46f9a31a278aa1872e120228d43d4567d8d. 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-17 22:25:54 -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#31534