Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use react-query to fetch permissions with usePermissions #8196

Merged
merged 8 commits into from
Sep 28, 2022

Conversation

hiaselhans
Copy link
Contributor

@hiaselhans hiaselhans commented Sep 26, 2022

I wanted to hook up the builtin permission system from react-admin and I experienced a ton of queries: one per permission check.
the docs have a hidden (pro/paid flagged) hint on how to solve this:
https://marmelab.com/react-admin/AuthRBAC.html#performance

since we are using react-query already all-over why don't we use it for the permission-fetching?
This adds a lot of sane defaults: re-fetch on window focus, cache invalidation on logout, retries with back-off, ...

I think the same could be applied to useCheckAuth, useGetIdentity,... but I'd like to hear your comments first.

@hiaselhans hiaselhans changed the title Permissions usequery [ra-core] use react-query useQuery for permissions fetching Sep 26, 2022
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This is definitely something we wanted to do, so it's nice of you to tackle this.

packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.spec.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
@fzaninotto
Copy link
Member

Nice! Waiting for a second review to merge.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks

packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
@slax57 slax57 added this to the 4.4.0 milestone Sep 28, 2022
@slax57 slax57 merged commit e0a3104 into marmelab:next Sep 28, 2022
@slax57 slax57 changed the title [ra-core] use react-query useQuery for permissions fetching Use react-query to fetch permissions with usePermissions Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants