[PR #6064] [CLOSED] feat(plugin):Implement Conditional Plugin Activation with enabled Flag #6418

Closed
opened 2026-03-13 12:58:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6064
Author: @Ridhim-RR
Created: 11/18/2025
Status: Closed

Base: canaryHead: conditional-plugin-activation


📝 Commits (10+)

  • de47ee0 feat(plugin):Implement Conditional Plugin Activation with enabled Flag
  • b9394f3 Update packages/better-auth/src/context/create-context.test.ts
  • 67f67c1 Merge branch 'canary' into conditional-plugin-activation
  • 5be087c fix(types): exclude disabled plugins from type inference
  • af7ec1a Merge branch 'conditional-plugin-activation' of https://github.com/Ridhim-RR/better-auth into conditional-plugin-activation
  • 563ee8d chore(lint):linting issue resolved
  • 64da085 Merge branch 'canary' into conditional-plugin-activation
  • d45880c Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into conditional-plugin-activation
  • 3ff6ac8 Merge branch 'canary' into conditional-plugin-activation
  • cc216c7 fix(test&lint): test case and linting issue resolved

📊 Changes

8 files changed (+78 additions, -25 deletions)

View changed files

📝 packages/better-auth/src/client/config.ts (+6 -2)
📝 packages/better-auth/src/context/create-context.test.ts (+35 -1)
📝 packages/better-auth/src/context/create-context.ts (+4 -2)
📝 packages/better-auth/src/types/helper.ts (+8 -0)
📝 packages/better-auth/src/types/models.ts (+14 -11)
📝 packages/better-auth/src/types/plugins.ts (+9 -9)
📝 packages/core/src/types/plugin-client.ts (+1 -0)
📝 packages/core/src/types/plugin.ts (+1 -0)

📄 Description

Closes #6040

Summary

This PR introduces an optional enabled?: boolean flag to plugin definitions, allowing runtime toggling of plugins without removing registrations or modifying build-time configurations.

Changes

  • Added optional enabled field to plugin types for explicit runtime enable/disable capability.
  • Updated makePlugin test helper in create-context.test.ts to improve typing with minimal, safe type casts.

Tests
Implemented tests in create-context.test.ts covering three scenarios:

  • enabled: false — plugin is skipped and does not initialize.
  • enabled: true — plugin initializes normally.
  • enabled not provided — maintains previous behavior (plugin initializes).

Note:
If the enabled key is omitted, the plugin behaves as before. If enabled is explicitly set to true, the plugin initializes as usual. If set to false, plugin initialization is skipped.


Summary by cubic

Adds an optional enabled flag to plugins for runtime activation or skipping without changing build-time config. Disabled plugins are filtered at runtime and excluded from type inference.

  • New Features

    • Added enabled?: boolean to BetterAuthPlugin and BetterAuthClientPlugin.
    • Runtime filtering in createAuthContext and client config excludes plugins with enabled === false, including fetchPlugins.
    • Types updated to exclude disabled plugins from inference (InferServerPlugin, $Infer, and error codes).
  • Migration

    • No changes required. Omit enabled or set true to keep current behavior; set enabled: false to disable a plugin without removing its registration.

Written for commit fd36f6dbc1. 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/6064 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 11/18/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `conditional-plugin-activation` --- ### 📝 Commits (10+) - [`de47ee0`](https://github.com/better-auth/better-auth/commit/de47ee07cb28060036210e02012073df8eb6f8fb) feat(plugin):Implement Conditional Plugin Activation with enabled Flag - [`b9394f3`](https://github.com/better-auth/better-auth/commit/b9394f3c6444fc42fe739e65860a4b4b1c0c53f5) Update packages/better-auth/src/context/create-context.test.ts - [`67f67c1`](https://github.com/better-auth/better-auth/commit/67f67c1ae1a60f781029252f8ba7a839b7778386) Merge branch 'canary' into conditional-plugin-activation - [`5be087c`](https://github.com/better-auth/better-auth/commit/5be087c81d79c10a3adbdcdbb1b3e14fcf60473a) fix(types): exclude disabled plugins from type inference - [`af7ec1a`](https://github.com/better-auth/better-auth/commit/af7ec1a7aa4b930a34b06b7bcf10320146f17c97) Merge branch 'conditional-plugin-activation' of https://github.com/Ridhim-RR/better-auth into conditional-plugin-activation - [`563ee8d`](https://github.com/better-auth/better-auth/commit/563ee8d23db80c6030b2e6e6dc748dfa7957c9fa) chore(lint):linting issue resolved - [`64da085`](https://github.com/better-auth/better-auth/commit/64da0850ea66575e36ed36b3cf307b48f1ee54da) Merge branch 'canary' into conditional-plugin-activation - [`d45880c`](https://github.com/better-auth/better-auth/commit/d45880c56845a423bed9a242e0abcdc1270e9363) Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into conditional-plugin-activation - [`3ff6ac8`](https://github.com/better-auth/better-auth/commit/3ff6ac819cea29d04503808acd8eeee009a6dc81) Merge branch 'canary' into conditional-plugin-activation - [`cc216c7`](https://github.com/better-auth/better-auth/commit/cc216c7db74c386c91722f9ad2c89a19890a765d) fix(test&lint): test case and linting issue resolved ### 📊 Changes **8 files changed** (+78 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/client/config.ts` (+6 -2) 📝 `packages/better-auth/src/context/create-context.test.ts` (+35 -1) 📝 `packages/better-auth/src/context/create-context.ts` (+4 -2) 📝 `packages/better-auth/src/types/helper.ts` (+8 -0) 📝 `packages/better-auth/src/types/models.ts` (+14 -11) 📝 `packages/better-auth/src/types/plugins.ts` (+9 -9) 📝 `packages/core/src/types/plugin-client.ts` (+1 -0) 📝 `packages/core/src/types/plugin.ts` (+1 -0) </details> ### 📄 Description Closes #6040 ### Summary This PR introduces an optional enabled?: boolean flag to plugin definitions, allowing runtime toggling of plugins without removing registrations or modifying build-time configurations. **Changes** - Added optional enabled field to plugin types for explicit runtime enable/disable capability. - Updated makePlugin test helper in create-context.test.ts to improve typing with minimal, safe type casts. **Tests** Implemented tests in create-context.test.ts covering three scenarios: - enabled: false — plugin is skipped and does not initialize. - enabled: true — plugin initializes normally. - enabled not provided — maintains previous behavior (plugin initializes). **Note:** If the enabled key is omitted, the plugin behaves as before. If enabled is explicitly set to true, the plugin initializes as usual. If set to false, plugin initialization is skipped. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds an optional enabled flag to plugins for runtime activation or skipping without changing build-time config. Disabled plugins are filtered at runtime and excluded from type inference. - **New Features** - Added enabled?: boolean to BetterAuthPlugin and BetterAuthClientPlugin. - Runtime filtering in createAuthContext and client config excludes plugins with enabled === false, including fetchPlugins. - Types updated to exclude disabled plugins from inference (InferServerPlugin, $Infer, and error codes). - **Migration** - No changes required. Omit enabled or set true to keep current behavior; set enabled: false to disable a plugin without removing its registration. <sup>Written for commit fd36f6dbc10829d8dd25945172e2925d0286d07f. 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-03-13 12:58:35 -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#6418