mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-23 07:18:56 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user