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 useLogoutIfAccessDenied may notify more than once #6144

Merged
merged 1 commit into from
Apr 10, 2021

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Apr 9, 2021

Problem

When the dataProvider returns with an auth error (e.g. a 403 response), react-admin triggers a redirection to the login page and a notification message that the auth params are no longer valid.

Your session has ended, please reconnect

image

This happens when the API invalidates the user credentials.

Now, if a page needs more than one dataProvider Request, this will cause several logouts (not a problem) and several notifications about auth params (that's a problem).

Solution

Check that the user is authenticated before notifying that their auth params are no longer valid

@fzaninotto fzaninotto added the RFR Ready For Review label Apr 9, 2021
@@ -8,6 +8,12 @@ const dataProvider = fakeRestProvider(data, true);
const uploadCapableDataProvider = addUploadFeature(dataProvider);
const sometimesFailsDataProvider = new Proxy(uploadCapableDataProvider, {
get: (target, name) => (resource, params) => {
// set session_ended=true in localStorage to trigger an API auth error
if (localStorage.getItem('session_ended')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this gives a way to simulate an API which invalidates credentials


const logout = jest.fn();
Copy link
Member Author

Choose a reason for hiding this comment

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

this was a bad idea and made me loose 1 hour scratching my head. Using authProvider.logout() in useLogout is way more natural.

@djhi djhi added this to the 3.14.3 milestone Apr 10, 2021
@djhi djhi merged commit 8cba994 into master Apr 10, 2021
@djhi djhi deleted the fix-multiple-notifications-on-checkError branch April 10, 2021 07:01
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.

2 participants