[PR #6095] [CLOSED] Bugfix/has permission silent false missing role #14688

Closed
opened 2026-04-13 09:35:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: canaryHead: bugfix/hasPermission-silent-false-missing-role


📝 Commits (8)

  • 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
  • 3816c69 fix(role):hasPermission-silent-false-missing-role
  • 0c3511e Merge branch 'canary' into bugfix/hasPermission-silent-false-missing-role

📊 Changes

12 files changed (+126 additions, -30 deletions)

View changed files

📝 docs/content/docs/plugins/organization.mdx (+23 -0)
📝 packages/better-auth/src/client/config.ts (+6 -2)
📝 packages/better-auth/src/client/plugins/infer-plugin.ts (+3 -4)
📝 packages/better-auth/src/context/create-context.test.ts (+33 -1)
📝 packages/better-auth/src/context/create-context.ts (+4 -2)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+14 -1)
📝 packages/better-auth/src/plugins/organization/permission.ts (+7 -0)
📝 packages/better-auth/src/types/helper.ts (+11 -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 #6081

This PR improves runtime behavior and documentation for custom roles in the organization plugin:

  • hasPermission now returns false for missing or unknown roles and logs a client-side warning via console.warn to help developers debug.
  • Clarifies in organization.mdx that supplying customRoles replaces the built-in default roles unless explicitly merged.
  • Adds an example showing how to merge defaultRoles with custom roles using the spread operator (...defaultRoles).
  • Adds a test case in organization.test.ts to verify this behavior.

Files Changed

  • permission.ts — Updated hasPermissionFn to log warnings for unknown roles while returning false.
  • organization.test.ts — Added tests confirming warnings and correct behavior for unknown roles.
  • organization.mdx — Documentation enhancements clarifying role merging and hasPermission behavior.

Summary by cubic

Fix permission checks for unknown roles by returning false and logging a warning, and clarify that custom roles replace defaults unless merged. Also add conditional plugin activation with an enabled flag and update types to ignore disabled plugins.

  • Bug Fixes

    • hasPermission returns false and logs console.warn for missing/unknown roles.
    • Docs clarify custom roles replace defaults and show merging with defaultRoles.
    • Tests cover warning and behavior.
  • New Features

    • Plugins support enabled?: boolean; disabled plugins don’t init or contribute fetchPlugins.
    • Client/server filter plugins by enabled; type inference excludes disabled plugins.
    • Added helper types to infer only enabled plugins.

Written for commit 3816c69d99. 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/6095 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 11/19/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `bugfix/hasPermission-silent-false-missing-role` --- ### 📝 Commits (8) - [`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 - [`3816c69`](https://github.com/better-auth/better-auth/commit/3816c69d9917e26b76a723fbb670a441d7cb5b6b) fix(role):hasPermission-silent-false-missing-role - [`0c3511e`](https://github.com/better-auth/better-auth/commit/0c3511e9ae333ab672f5bfc96c41f46203cbc28c) Merge branch 'canary' into bugfix/hasPermission-silent-false-missing-role ### 📊 Changes **12 files changed** (+126 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/organization.mdx` (+23 -0) 📝 `packages/better-auth/src/client/config.ts` (+6 -2) 📝 `packages/better-auth/src/client/plugins/infer-plugin.ts` (+3 -4) 📝 `packages/better-auth/src/context/create-context.test.ts` (+33 -1) 📝 `packages/better-auth/src/context/create-context.ts` (+4 -2) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+14 -1) 📝 `packages/better-auth/src/plugins/organization/permission.ts` (+7 -0) 📝 `packages/better-auth/src/types/helper.ts` (+11 -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 #6081 This PR improves runtime behavior and documentation for custom roles in the organization plugin: - hasPermission now returns false for missing or unknown roles and logs a client-side warning via console.warn to help developers debug. - Clarifies in organization.mdx that supplying customRoles replaces the built-in default roles unless explicitly merged. - Adds an example showing how to merge defaultRoles with custom roles using the spread operator (...defaultRoles). - Adds a test case in organization.test.ts to verify this behavior. **Files Changed** - permission.ts — Updated hasPermissionFn to log warnings for unknown roles while returning false. - organization.test.ts — Added tests confirming warnings and correct behavior for unknown roles. - organization.mdx — Documentation enhancements clarifying role merging and hasPermission behavior. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix permission checks for unknown roles by returning false and logging a warning, and clarify that custom roles replace defaults unless merged. Also add conditional plugin activation with an enabled flag and update types to ignore disabled plugins. - **Bug Fixes** - hasPermission returns false and logs console.warn for missing/unknown roles. - Docs clarify custom roles replace defaults and show merging with defaultRoles. - Tests cover warning and behavior. - **New Features** - Plugins support enabled?: boolean; disabled plugins don’t init or contribute fetchPlugins. - Client/server filter plugins by enabled; type inference excludes disabled plugins. - Added helper types to infer only enabled plugins. <sup>Written for commit 3816c69d9917e26b76a723fbb670a441d7cb5b6b. 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-04-13 09:35:09 -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#14688