Extending organization schema - default value of false doesn't get added #1700

Closed
opened 2026-03-13 08:57:24 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @cpolanish on GitHub (Aug 13, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Initialize an auth object with the organization plugin and MongoDB adapter, and add an additional field of type boolean with a default value of false.

Current vs. Expected behavior

When I set a default value to a boolean false, the additional field does not get added to the Mongo document. If I default the value to a boolean true or a string, it does get added. It should add the field as a boolean false if specified.

What version of Better Auth are you using?

1.3.5

System info

Windows 11

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

Backend

Auth config (if applicable)

export const auth: ReturnType<typeof betterAuth> = betterAuth({
  database: mongodbAdapter(db),
  trustedOrigins: ['http://localhost:5173'],
  plugins: [
    admin(),
    organization({
      schema: {
        organization: {
          additionalFields: {
            inactive: {
              type: 'boolean',
              required: true,
              input: false,
              defaultValue: false,
            },
          },
        },
      },
    }),
  ],
  emailAndPassword: {
    enabled: true,
  },
});

Additional context

No response

Originally created by @cpolanish on GitHub (Aug 13, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Initialize an auth object with the organization plugin and MongoDB adapter, and add an additional field of type boolean with a default value of false. ### Current vs. Expected behavior When I set a default value to a boolean false, the additional field does not get added to the Mongo document. If I default the value to a boolean true or a string, it does get added. It should add the field as a boolean false if specified. ### What version of Better Auth are you using? 1.3.5 ### System info ```bash Windows 11 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth: ReturnType<typeof betterAuth> = betterAuth({ database: mongodbAdapter(db), trustedOrigins: ['http://localhost:5173'], plugins: [ admin(), organization({ schema: { organization: { additionalFields: { inactive: { type: 'boolean', required: true, input: false, defaultValue: false, }, }, }, }, }), ], emailAndPassword: { enabled: true, }, }); ``` ### Additional context _No response_
GiteaMirror added the adapter label 2026-03-13 08:57:24 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 13, 2025):

This is a known issue in Better Auth: when you set a default value of false for a boolean field in the organization schema, it doesn't get added to the MongoDB document because the framework's logic checks for truthy values instead of explicitly checking for undefined. This causes falsy values like false to be skipped during document creation, while true and strings work as expected. The documentation confirms that defaultValue only applies in the JavaScript layer, so the database field remains optional and may not be set automatically see docs.

There's an open pull request to fix this by checking for undefined rather than truthy values, which will ensure false and 0 are handled correctly see PR. Until this is merged and released, the best workaround is to explicitly set the field to false in your application logic when creating organizations. This will ensure the field is present in your MongoDB documents.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Aug 13, 2025): <!-- Answer --> This is a known issue in Better Auth: when you set a default value of `false` for a boolean field in the organization schema, it doesn't get added to the MongoDB document because the framework's logic checks for truthy values instead of explicitly checking for `undefined`. This causes falsy values like `false` to be skipped during document creation, while `true` and strings work as expected. The documentation confirms that `defaultValue` only applies in the JavaScript layer, so the database field remains optional and may not be set automatically [see docs](https://better-auth.com/docs/concepts/database). There's an open pull request to fix this by checking for `undefined` rather than truthy values, which will ensure `false` and `0` are handled correctly [see PR](https://github.com/better-auth/better-auth/pull/3512). Until this is merged and released, the best workaround is to explicitly set the field to `false` in your application logic when creating organizations. This will ensure the field is present in your MongoDB documents. <!-- 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/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5f6f1b61-107b-4327-8be6-7dd9e3f18fda?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/3984)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1700