Skip to content

Conversation

@slax57
Copy link
Contributor

@slax57 slax57 commented Dec 3, 2024

Problem

Consider an Admin that has some pages that allow anonymous access, and also a authProvider.getPermissions() implementation, that, say, returns 'user' when the user is logged in, and undefined when the user is not logged in.

If the user first accesses the anonymous parts of the Admin, the cached permission will be undefined. But if he then logs in, without leaving the Admin, then the cache is not updated, and the permissions still return undefined instead of 'user'.

Solution

Invalidate the getPermissions cache after a successful login, to force a refetch of the permissions.

How To Test

https://react-admin-storybook-31pnpeyju-marmelab.vercel.app/?path=/story/ra-core-auth-uselogin--permissions-state

Additional Checks

  • The PR targets master for a bugfix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date -> no need, bugfix

Also, please make sure to read the contributing guidelines.

@slax57 slax57 added the RFR Ready For Review label Dec 3, 2024
retry: false,
};
const res = usePermissions({}, permissionQueryParams);
return children(res);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use a child function here? You could just return the JSX you have in inspectPermissionsState, couldn't you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't give it too much though TBH, I just copied that code from the usePermissions stories

@djhi djhi added this to the 5.4.2 milestone Dec 3, 2024
@djhi djhi merged commit 66dbf99 into master Dec 3, 2024
13 checks passed
@djhi djhi deleted the login-getPermissions-cache branch December 3, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants