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
This commit is contained in:
Bereket Engida
2026-02-18 15:13:49 -08:00
parent 72ec62ff06
commit 54dc125f55

View File

@@ -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;
}