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

Fix <Admin> should call authProvider.getPermissions only when given a child function #9001

Merged
merged 7 commits into from
Jun 14, 2023

Conversation

adguernier
Copy link
Contributor

@adguernier adguernier commented Jun 13, 2023

When creating a React Admin App with create-react-admin, and choosing to add an authProvider, the provider is created with this method: getPermissions: () => Promise.reject("Unknown method"),.
This leads to an error log in browser devtools console (e.g: Unknown method), even the app doesn't need permission anywhere.

Reproduce:

  • Create a React Admin App with create-react-admin
  • Run the app, go on the app with a browser and open browser devtools
  • Wait some second and see the error throws in the console

Fix: Call authProvider.getPermissions only when a child function exist and only when the hook usePermissions is used in the application.

Fix: change authProvider template in create-react-admin package

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.

Good catch!

@adguernier adguernier added WIP Work In Progress and removed RFR Ready For Review labels Jun 13, 2023
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
packages/ra-core/src/auth/usePermissions.ts Outdated Show resolved Hide resolved
@djhi djhi changed the title Fix: query permissions at statup only when a child function exist Fix: query permissions at startup only when a child function exist Jun 13, 2023
Comment on lines 33 to 34
const role = localStorage.getItem('permissions');
return role ? Promise.resolve(role) : Promise.reject();
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO you should just resolve with undefined as we don't set those permissions anywhere

@djhi djhi added this to the 4.11.3 milestone Jun 14, 2023
@adguernier adguernier added RFR Ready For Review and removed WIP Work In Progress labels Jun 14, 2023
@djhi djhi merged commit ac1f2a3 into master Jun 14, 2023
8 checks passed
@djhi djhi deleted the fix-query-permissions-only-when-needed branch June 14, 2023 07:35
@slax57 slax57 changed the title Fix: query permissions at startup only when a child function exist Fix <Admin> should call authProvider.getPermissions only when given a child function Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants