I created a custom page which updates the user name. It gets updated successfully both in my controlled TextField component and in the database. But the name doesn't get updated in the Appbar instantly. If I reload the page then the User name gets updated.
I configured my authProvider.getIdentity() as follows in the authProvider.js file
const authProvider = {
......
getIdentity: () => {
try {
const { _id, name } = JSON.parse(localStorage.getItem("auth")).user;
return Promise.resolve({ id: _id, fullName: name });
} catch (error) {
return Promise.reject(error);
}
},
......
};
export default authProvider;
This authProvider gets the name from the localStorage and displays the name fine. Is there any way to call this getIdentity method manually to get the updated user info? My Custom page's fetch API updates the localStorage instantly which gets updated in the Appbar but after a reload. Is there any other way?
In case needed, the fetch API of my custom page is as follows:
fetch('/my-api')..then(...)
.then(
....
localStorage.setItem("auth", JSON.stringify(data)); //-> setting the user value in local Storage
....
})