From 54dc125f55cbddbee180fa7fd00332b5d0cf4a91 Mon Sep 17 00:00:00 2001 From: Bereket Engida <86073083+Bekacru@users.noreply.github.com> Date: Wed, 18 Feb 2026 15:13:49 -0800 Subject: [PATCH] fix(organization): add warning for missing roles in hasPermission When a role is not found in the configured roles, log a warning with the missing role name and available roles. This helps developers debug configuration issues when custom roles override defaults or when database roles don't match configuration. Fixes #6081 --- .../better-auth/src/plugins/organization/permission.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/better-auth/src/plugins/organization/permission.ts b/packages/better-auth/src/plugins/organization/permission.ts index a82decee52..9d900e1e2e 100644 --- a/packages/better-auth/src/plugins/organization/permission.ts +++ b/packages/better-auth/src/plugins/organization/permission.ts @@ -18,7 +18,13 @@ export const hasPermissionFn = ( for (const role of roles) { const _role = acRoles[role as keyof typeof acRoles]; - const result = _role?.authorize(input.permissions); + if (!_role) { + console.warn( + `[Better Auth] [hasPermission] Role "${role}" not found in configured roles. Available roles: ${Object.keys(acRoles).join(", ")}`, + ); + continue; + } + const result = _role.authorize(input.permissions); if (result?.success) { return true; }