[PR #8065] fix(organization): hasPermission silent return false when role not found #15967

Open
opened 2026-04-13 10:19:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8065
Author: @himself65
Created: 2/19/2026
Status: 🔄 Open

Base: mainHead: himself65/2026/02/19/role


📝 Commits (4)

  • c0ce4f2 fix(organization): hasPermission silent return false when role not found
  • f293770 Update packages/better-auth/src/plugins/organization/permission.ts
  • b383fca Merge branch 'canary' into himself65/2026/02/19/role
  • e2938d2 Merge branch 'main' into himself65/2026/02/19/role

📊 Changes

10 files changed (+133 additions, -37 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/client.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/has-permission.ts (+4 -1)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+58 -0)
📝 packages/better-auth/src/plugins/organization/organization.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/permission.ts (+40 -6)
📝 packages/better-auth/src/plugins/organization/routes/crud-access-control.ts (+17 -16)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+5 -5)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/6081


Summary by cubic

Returns structured results from permission checks and returns clear errors when a role is unknown, instead of silently returning false. All org routes now check result.success; the client helper returns a boolean. Fixes #6081.

  • Bug Fixes

    • hasPermissionFn now returns { success, error?, missingRoles? } and reports unknown roles with available role names.
    • Server hasPermission exports HasPermissionResult; org API responds with { success, error }.
    • Updated all route guards and access-control utilities to use result.success; clientSideHasPermission returns result.success.
    • Added tests for the undefined-role case to assert the error message.
  • Migration

    • If you call hasPermission/hasPermissionFn directly, check result.success and handle result.error when present.

Written for commit e2938d29d6. Summary will update 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/8065 **Author:** [@himself65](https://github.com/himself65) **Created:** 2/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `himself65/2026/02/19/role` --- ### 📝 Commits (4) - [`c0ce4f2`](https://github.com/better-auth/better-auth/commit/c0ce4f21ec8d57fe5b7ab05a7f1d6801d2a2e172) fix(organization): `hasPermission` silent return false when role not found - [`f293770`](https://github.com/better-auth/better-auth/commit/f293770d52c0daa6189ed3d7d895094aa846756a) Update packages/better-auth/src/plugins/organization/permission.ts - [`b383fca`](https://github.com/better-auth/better-auth/commit/b383fca88890c70c81e0cb286142c8d57f90230d) Merge branch 'canary' into himself65/2026/02/19/role - [`e2938d2`](https://github.com/better-auth/better-auth/commit/e2938d29d64917381dec0972b9f06caa5b800543) Merge branch 'main' into himself65/2026/02/19/role ### 📊 Changes **10 files changed** (+133 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/client.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/has-permission.ts` (+4 -1) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+58 -0) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/permission.ts` (+40 -6) 📝 `packages/better-auth/src/plugins/organization/routes/crud-access-control.ts` (+17 -16) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+5 -5) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/6081 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Returns structured results from permission checks and returns clear errors when a role is unknown, instead of silently returning false. All org routes now check result.success; the client helper returns a boolean. Fixes #6081. - **Bug Fixes** - hasPermissionFn now returns { success, error?, missingRoles? } and reports unknown roles with available role names. - Server `hasPermission` exports `HasPermissionResult`; org API responds with { success, error }. - Updated all route guards and access-control utilities to use result.success; `clientSideHasPermission` returns result.success. - Added tests for the undefined-role case to assert the error message. - **Migration** - If you call hasPermission/hasPermissionFn directly, check result.success and handle result.error when present. <sup>Written for commit e2938d29d64917381dec0972b9f06caa5b800543. Summary will update 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 10:19:50 -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#15967