Conditional Plugin Activation with enabled Flag #2323

Closed
opened 2026-03-13 09:44:01 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @bishwajitcadhikary on GitHub (Nov 17, 2025).

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

Summary
Introduce an enabled boolean flag in plugin configuration so developers can toggle a plugin on or off without removing its code or modifying environment-specific logic.

Why This Matters
Right now, once a plugin is registered, it runs—there’s no built-in way to disable it conditionally. This becomes annoying when you’re managing different environments (dev/staging/production) or running partial setups. Having to remove or comment out plugin registrations isn’t ideal, and conditional if wrappers around plugin imports get messy fast.

A simple enabled flag would solve this cleanly.

Proposed API Shape

betterAuth({
  plugins: [
    somePlugin({
      enabled: process.env.FEATURE_X_ENABLED === "true",
      ...otherOptions
    })
  ]
})

Expected Behavior
• If enabled: true, the plugin initializes and behaves normally.
• If enabled: false, the plugin is skipped entirely—no setup, no side effects.

Benefits
• Cleaner configuration management
• Easier environment-based toggling
• More flexible feature rollout/rollback
• Reduces boilerplate conditionals around plugin registration
• Improves DX by making plugin behavior explicit and predictable

Expected Behavior
• If enabled: true, the plugin initializes and behaves normally.
• If enabled: false, the plugin is skipped entirely—no setup, no side effects.

Benefits
• Cleaner configuration management
• Easier environment-based toggling
• More flexible feature rollout/rollback
• Reduces boilerplate conditionals around plugin registration
• Improves DX by making plugin behavior explicit and predictable

Notes
• This is consistent with patterns used in many plugin-based ecosystems.
• Should not introduce breaking changes if default behavior remains enabled: true.
• This is consistent with patterns used in many plugin-based ecosystems.
• Should not introduce breaking changes if default behavior remains enabled: true.

Describe alternatives you've considered

No

Additional context

No response

Originally created by @bishwajitcadhikary on GitHub (Nov 17, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like **Summary** Introduce an enabled boolean flag in plugin configuration so developers can toggle a plugin on or off without removing its code or modifying environment-specific logic. **Why This Matters** Right now, once a plugin is registered, it runs—there’s no built-in way to disable it conditionally. This becomes annoying when you’re managing different environments (dev/staging/production) or running partial setups. Having to remove or comment out plugin registrations isn’t ideal, and conditional if wrappers around plugin imports get messy fast. A simple enabled flag would solve this cleanly. **Proposed API Shape** ```ts betterAuth({ plugins: [ somePlugin({ enabled: process.env.FEATURE_X_ENABLED === "true", ...otherOptions }) ] }) ``` **Expected Behavior** • If enabled: true, the plugin initializes and behaves normally. • If enabled: false, the plugin is skipped entirely—no setup, no side effects. **Benefits** • Cleaner configuration management • Easier environment-based toggling • More flexible feature rollout/rollback • Reduces boilerplate conditionals around plugin registration • Improves DX by making plugin behavior explicit and predictable Expected Behavior • If enabled: true, the plugin initializes and behaves normally. • If enabled: false, the plugin is skipped entirely—no setup, no side effects. Benefits • Cleaner configuration management • Easier environment-based toggling • More flexible feature rollout/rollback • Reduces boilerplate conditionals around plugin registration • Improves DX by making plugin behavior explicit and predictable Notes • This is consistent with patterns used in many plugin-based ecosystems. • Should not introduce breaking changes if default behavior remains enabled: true. • This is consistent with patterns used in many plugin-based ecosystems. • Should not introduce breaking changes if default behavior remains enabled: true. ### Describe alternatives you've considered No ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:44:02 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025):

tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025): tag @better-auth-agent if you would like an answer from the Agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bishwajitcadhikary commented on GitHub (Nov 17, 2025):

@better-auth-agent

@bishwajitcadhikary commented on GitHub (Nov 17, 2025): @better-auth-agent
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025):

Hi there, thanks for the suggestion! It sounds like adding an "enabled" flag to plugin configurations would really help manage environment-based setups by simply toggling functionality without additional conditional logic. From your description, when the flag is set to false, the plugin would not initialize or trigger any side effects, while leaving the default behavior unchanged when true. This streamlined approach could indeed improve DX and flexibility while reducing clutter in the configuration code [1].

Could you share any specific environments or scenarios where you encountered issues that motivated this request? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025): Hi there, thanks for the suggestion! It sounds like adding an "enabled" flag to plugin configurations would really help manage environment-based setups by simply toggling functionality without additional conditional logic. From your description, when the flag is set to false, the plugin would not initialize or trigger any side effects, while leaving the default behavior unchanged when true. This streamlined approach could indeed improve DX and flexibility while reducing clutter in the configuration code [[1]](https://github.com/better-auth/better-auth/issues/917). Could you share any specific environments or scenarios where you encountered issues that motivated this request? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bishwajitcadhikary commented on GitHub (Nov 17, 2025):

Sure — the main cases where this bites me are environment-based setups. For example, in development I might want certain plugins active (like logging or mock providers), but in production I need them completely disabled without removing code. Same with staging or preview environments where only part of the plugin stack should run. Having a simple enabled flag keeps the config clean and avoids wrapping half the plugin list in conditionals.
@better-auth-agent

@bishwajitcadhikary commented on GitHub (Nov 17, 2025): Sure — the main cases where this bites me are environment-based setups. For example, in development I might want certain plugins active (like logging or mock providers), but in production I need them completely disabled without removing code. Same with staging or preview environments where only part of the plugin stack should run. Having a simple enabled flag keeps the config clean and avoids wrapping half the plugin list in conditionals. @better-auth-agent
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025):

Hello and thanks for opening this issue! We understand you’d like to see an "enabled" flag as part of the plugin configuration so that plugins can be conditionally activated, which would help simplify environment-based setups by removing the need for wrapped conditionals. Your proposal for having the plugin initialization completely skipped when enabled is clear and aligns with patterns seen in many other ecosystems [1].

Our team is currently reviewing various enhancement requests, and this one is on our radar. As a short-term workaround, wrapping the plugin registration in an environment check before passing it to the Better Auth configuration is an option. For instance:

• If process.env.FEATURE_X_ENABLED is "true", register the plugin; if not, omit it in your plugin list.

We’ll work on formalizing this pattern in a future release, ensuring there’s no breaking change when the flag defaults to true.

Could you let us know if you have any additional use cases or specific scenarios in mind where this configurable toggle would be especially beneficial? Tag @bekacru and @ping__ if you’d like more input from our team.

tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 17, 2025): Hello and thanks for opening this issue! We understand you’d like to see an "enabled" flag as part of the plugin configuration so that plugins can be conditionally activated, which would help simplify environment-based setups by removing the need for wrapped conditionals. Your proposal for having the plugin initialization completely skipped when enabled is clear and aligns with patterns seen in many other ecosystems [[1]](https://github.com/better-auth/better-auth/issues/917). Our team is currently reviewing various enhancement requests, and this one is on our radar. As a short-term workaround, wrapping the plugin registration in an environment check before passing it to the Better Auth configuration is an option. For instance: • If process.env.FEATURE_X_ENABLED is "true", register the plugin; if not, omit it in your plugin list. We’ll work on formalizing this pattern in a future release, ensuring there’s no breaking change when the flag defaults to true. Could you let us know if you have any additional use cases or specific scenarios in mind where this configurable toggle would be especially beneficial? Tag @bekacru and @ping__ if you’d like more input from our team. tag @better-auth-agent if you would like an answer from the Agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@Ridhim-RR commented on GitHub (Nov 18, 2025):

Working on it

@Ridhim-RR commented on GitHub (Nov 18, 2025): Working on it
Author
Owner
@himself65 commented on GitHub (Dec 26, 2025): https://github.com/better-auth/better-auth/pull/6064#pullrequestreview-3612931730
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2323