Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

ping-maxwell
Copy link
Member

@ping-maxwell ping-maxwell commented Oct 15, 2025

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:
#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 provided attributes into existing field definitions.
  • Migration

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

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
                        }
                    }
                }
            }
        })
    ]
})
```
Copy link

vercel bot commented Oct 15, 2025

@ping-maxwell is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Oct 15, 2025

Open in StackBlitz

better-auth

npm i https://pkg.pr.new/better-auth/better-auth@5330

@better-auth/cli

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/cli@5330

@better-auth/core

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/core@5330

@better-auth/expo

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@5330

@better-auth/sso

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/sso@5330

@better-auth/stripe

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/stripe@5330

@better-auth/telemetry

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/telemetry@5330

commit: e0ab60a

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.