Skip to content

Commit

Permalink
Refactor useCanAccessResources
Browse files Browse the repository at this point in the history
  • Loading branch information
React-Admin CI committed Nov 20, 2024
1 parent f669e73 commit d30bc7c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/ra-core/src/auth/useCanAccessResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ export const useCanAccessResources = <
})
);

const canAccessMap = queries.reduce(
(acc, { resource, canAccess }) => {
acc[resource] = canAccess;
return acc;
},
{} as Record<string, boolean>
);

const result = resources.reduce(
(acc, resource) => ({
...acc,
[resource]:
queries.find(query => query.resource === resource)
?.canAccess ?? false,
[resource]: canAccessMap[resource],
}),
{} as Record<string, boolean>
);
Expand Down

0 comments on commit d30bc7c

Please sign in to comment.