I’ve implemented a AuthProvider.js in my React-Admin application and I’d like to delay the logout process by, say 5 seconds, and during that time period show a modal that says "logging out…".
For context, here’s the example from the docs:
logout: () => {
localStorage.removeItem('username');
return Promise.resolve();
},
I’ve set my AuthProvider.js to delay the logout process by seconds with following code:
logout: () => {
// [add code here to show a modal]
return new Promise(resolve => {
setTimeout(() => {
localStorage.removeItem('username');
// [add code here to hide the modal]
resolve();
}, 5000); // add a delay of 5 seconds
});
},
Is there any way to show the user a modal of some kind during the delay (see "add code here" comments)?
2
Answers
I think you can add some state like this
make a custom hook
then
then create a modal component that is conditionally rendered based on the value of isLoggingOut.
You need to implement communication between AuthProvider and React Component. You can do this with closure. for example:
then in your React component
you can use redux to dispatch event into your React component