[PR #6097] [CLOSED] fix(hasPermission): implement unknown-role-warning #14689

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

📋 Pull Request Information

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

Base: canaryHead: bugfix/6081-hasPermission-unknown-role-warning


📝 Commits (4)

  • 6a11b6f fix(hasPermission): implement unknown-role-warning
  • 7071325 chore(lint): linting issue resolved
  • da159fd fix: revert the chnages in the docs, user ctx.context.logger
  • 0b230fa Merge branch 'canary' into bugfix/6081-hasPermission-unknown-role-warning

📊 Changes

3 files changed (+38 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/has-permission.ts (+4 -1)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+14 -1)
📝 packages/better-auth/src/plugins/organization/permission.ts (+20 -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

Adds a warning in hasPermission for unknown roles and returns false instead of throwing. Uses ctx.context.logger when available, otherwise console.warn. Addresses #6081.

  • Bug Fixes
    • Logs a warning for missing/unknown roles and returns false.
    • Added tests to verify the warning and behavior.

Written for commit 0b230faa5e. 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/6097 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 11/19/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `bugfix/6081-hasPermission-unknown-role-warning` --- ### 📝 Commits (4) - [`6a11b6f`](https://github.com/better-auth/better-auth/commit/6a11b6f4858797b31b510a29934e138cba6aab34) fix(hasPermission): implement unknown-role-warning - [`7071325`](https://github.com/better-auth/better-auth/commit/7071325e0594117b1776669cdfee0789292d18ac) chore(lint): linting issue resolved - [`da159fd`](https://github.com/better-auth/better-auth/commit/da159fd01058b08d71d4523fa77ff06463cd30e8) fix: revert the chnages in the docs, user ctx.context.logger - [`0b230fa`](https://github.com/better-auth/better-auth/commit/0b230faa5e4266c49f32f0302ce7b2fceb87b892) Merge branch 'canary' into bugfix/6081-hasPermission-unknown-role-warning ### 📊 Changes **3 files changed** (+38 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/has-permission.ts` (+4 -1) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+14 -1) 📝 `packages/better-auth/src/plugins/organization/permission.ts` (+20 -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 Adds a warning in hasPermission for unknown roles and returns false instead of throwing. Uses ctx.context.logger when available, otherwise console.warn. Addresses #6081. - **Bug Fixes** - Logs a warning for missing/unknown roles and returns false. - Added tests to verify the warning and behavior. <sup>Written for commit 0b230faa5e4266c49f32f0302ce7b2fceb87b892. 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:11 -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#14689