-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Add ability to refresh the user identity in useGetIdentity
#8372
Conversation
I considered exposing the Edit: I finally opted in to using |
useGetIdentity
Co-authored-by: Aníbal Svarcas <WiXSL@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes requests, otherwise I approve the main changes
const authProvider = useAuthProvider(); | ||
useEffect(() => { | ||
if (authProvider && typeof authProvider.getIdentity === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing typeof authProvider.getIdentity === 'function' check causes a tiny BC break.
We found there are console errors after upgrading pass 4.6 because we have never implemented the getIdentity method since it was introduced in #5180
In the previous pull request it says
The change is backward compatible (if the authProvider.getIdentity() method isn't implemented, the admin shows an anonymous user avatar with no name, as before).
In v4 upgrade guide it did not mention this method is now required to be implemented. I believe we should now add a note about that breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be very easy for us to catch the issue and implement the method.
Just for other users they should be aware when they upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out!
The getIdentity
function should remain optional, even in v4, so I believe we should reintroduce this check to avoid errors. I'll open a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is: #8509
Problem
If an application contains a form letting the current user update their name and/or avatar, developers may want to refresh the identity after the form is submitted. It is currently cumbersome as it implies adding a context on top of the app (cf https://marmelab.com/blog/2020/12/14/react-admin-v3-userprofile.html)
Solution
Use react-query to fetch the authProvider in
useGetIdentity
Sample code