[GH-ISSUE #4869] Organization schema is not properly created: Slug should be mandatory #27417

Closed
opened 2026-04-17 18:25:57 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @elvince on GitHub (Sep 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4869

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Add the organisation plugin as per the docs
  2. Do a generate
  3. check the schema

Current vs. Expected behavior

The slug is set as string? instead of string in the schema file
I'm using prisma.

What version of Better Auth are you using?

1.3.16

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26100",
    "cpuCount": 16,
    "cpuModel": "Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz",
    "totalMemory": "31.72 GB",
    "freeMemory": "15.49 GB"
  },
  "node": {
    "version": "v22.14.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @elvince on GitHub (Sep 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4869 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Add the organisation plugin as per the docs 2. Do a generate 3. check the schema ### Current vs. Expected behavior The slug is set as string? instead of string in the schema file I'm using prisma. ### What version of Better Auth are you using? 1.3.16 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26100", "cpuCount": 16, "cpuModel": "Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz", "totalMemory": "31.72 GB", "freeMemory": "15.49 GB" }, "node": { "version": "v22.14.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 18:25:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 24, 2025):

The reason the organization schema's slug field is generated as optional (string?) in Prisma is because the Better Auth organization plugin does not set required: true for slug in its default schema configuration. The Prisma generator uses the required attribute to determine field optionality—if it's missing or set to false, the field becomes optional in the schema source, source.

To make slug mandatory, you need to explicitly set required: true for the slug field in your organization plugin schema config. For example:

organization({
  schema: {
    organization: {
      fields: {
        slug: {
          type: "string",
          required: true,
          unique: true,
          sortable: true
        }
      }
    }
  }
})

This will ensure the generated Prisma schema marks slug as required (String) instead of optional (String?). If you already have a custom schema config, just add required: true to the slug field definition.

Let me know if you need a full config example or run into any issues with this approach.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3326960513 --> @dosubot[bot] commented on GitHub (Sep 24, 2025): <!-- Answer --> The reason the organization schema's `slug` field is generated as optional (`string?`) in Prisma is because the Better Auth organization plugin does not set `required: true` for `slug` in its default schema configuration. The Prisma generator uses the `required` attribute to determine field optionality—if it's missing or set to false, the field becomes optional in the schema [`source`](https://github.com/better-auth/better-auth/issues/4751), [`source`](https://github.com/better-auth/better-auth/pull/4630). To make `slug` mandatory, you need to explicitly set `required: true` for the `slug` field in your organization plugin schema config. For example: ```typescript organization({ schema: { organization: { fields: { slug: { type: "string", required: true, unique: true, sortable: true } } } } }) ``` This will ensure the generated Prisma schema marks `slug` as required (`String`) instead of optional (`String?`). If you already have a custom schema config, just add `required: true` to the `slug` field definition. Let me know if you need a full config example or run into any issues with this approach. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c6c83d61-3370-4ba7-9909-28d62b23373c?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4869)
Author
Owner

@elvince commented on GitHub (Sep 24, 2025):

While this is a valid answer, there is a gap between the docs that set slug as mandatory and the reality with plug-in code.
What version is correct? docs or code?

In all cases this need to be fixed.

<!-- gh-comment-id:3328061693 --> @elvince commented on GitHub (Sep 24, 2025): While this is a valid answer, there is a gap between the docs that set slug as mandatory and the reality with plug-in code. What version is correct? docs or code? In all cases this need to be fixed.
Author
Owner

@dosubot[bot] commented on GitHub (Sep 24, 2025):

The code is the source of truth here: in the current organization plugin, the slug field is optional by default unless you explicitly set required: true in your config. The documentation implies slug should be mandatory, but that's not reflected in the actual implementation—so the code is correct and the docs need updating to match reality. If you want slug to be required, you should set required: true in your schema config. See the relevant code here.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3328072310 --> @dosubot[bot] commented on GitHub (Sep 24, 2025): <!-- Answer --> The code is the source of truth here: in the current organization plugin, the `slug` field is optional by default unless you explicitly set `required: true` in your config. The documentation implies `slug` should be mandatory, but that's not reflected in the actual implementation—so the code is correct and the docs need updating to match reality. If you want `slug` to be required, you should set `required: true` in your schema config. See the relevant code [here](https://github.com/better-auth/better-auth/blob/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b/packages/better-auth/src/plugins/organization/organization.ts). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/be307199-e2f5-40c6-ab4b-ade2fdf8bd27?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4869)
Author
Owner

@dvanmali commented on GitHub (Sep 24, 2025):

The schema marks slug as required. Remember to add the organization plugin to your schema.

export const auth = betterAuth({
    plugins: [ 
        organization() 
    ] 
})
<!-- gh-comment-id:3330673311 --> @dvanmali commented on GitHub (Sep 24, 2025): The [schema](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/plugins/organization/schema.ts) marks slug as required. Remember to add the `organization` plugin to your schema. ```ts export const auth = betterAuth({ plugins: [ organization() ] }) ```
Author
Owner

@elvince commented on GitHub (Sep 25, 2025):

@dvanmali
I already set properly the org plugins.

Did you manage with prisma, with org plugin set, to create the appropriate prisma schema with slug as string and not "string?" ?

This is the commande I used:
npx @better-auth/cli@latest generate --output ....\packages\database\prisma\models\better-auth.prisma --config ....\packages\lib\src\auth.ts

Thanks

<!-- gh-comment-id:3332494326 --> @elvince commented on GitHub (Sep 25, 2025): @dvanmali I already set properly the org plugins. Did you manage with prisma, with org plugin set, to create the appropriate prisma schema with slug as string and not "string?" ? This is the commande I used: npx @better-auth/cli@latest generate --output ..\..\packages\database\prisma\models\better-auth.prisma --config ..\..\packages\lib\src\auth.ts Thanks
Author
Owner

@joshsedl commented on GitHub (Dec 10, 2025):

I have the same issue. Can we please reopen this issue @dvanmali?

The Prisma schema is being generated incorrectly, when using the organization plugin. The "slug" is created as nullable:

model Organization {
  id          String       @id
  name        String
  slug        String?
  logo        String?
  createdAt   DateTime
  metadata    String?
  members     Member[]
  invitations Invitation[]

  @@unique([slug])
  @@map("organization")
}
<!-- gh-comment-id:3636936665 --> @joshsedl commented on GitHub (Dec 10, 2025): I have the same issue. Can we please reopen this issue @dvanmali? The Prisma schema is being generated incorrectly, when using the organization plugin. The "slug" is created as nullable: ~~~ model Organization { id String @id name String slug String? logo String? createdAt DateTime metadata String? members Member[] invitations Invitation[] @@unique([slug]) @@map("organization") } ~~~
Author
Owner

@JPustkuchen commented on GitHub (Dec 10, 2025):

Related issue: https://github.com/better-auth/better-auth/issues/6662

<!-- gh-comment-id:3637123325 --> @JPustkuchen commented on GitHub (Dec 10, 2025): Related issue: https://github.com/better-auth/better-auth/issues/6662
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27417