feat(logout): implement cache cleanup and service worker unregistration on logout
- Added a new utility, CacheCleanup, to handle clearing caches and unregistering the service worker during user logout. - Enhanced the LoggingOutPage to utilize CacheCleanup for clearing local session and caches before redirecting to the login page. - Introduced ModuleErrorBoundary to manage module loading errors, providing user feedback and options to retry or reload the application. - Updated App component to include global error handlers for improved error management related to module loading issues.
This commit is contained in:
@@ -331,6 +331,13 @@ self.addEventListener('message', event => {
|
||||
});
|
||||
break;
|
||||
|
||||
case 'LOGOUT':
|
||||
// Special handler for logout - clear all caches and unregister
|
||||
handleLogout().then(() => {
|
||||
event.ports[0].postMessage({ success: true });
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Service Worker: Unknown message type', type);
|
||||
}
|
||||
@@ -342,4 +349,19 @@ async function clearAllCaches() {
|
||||
console.log('Service Worker: All caches cleared');
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
// Clear all caches
|
||||
await clearAllCaches();
|
||||
|
||||
// Unregister the service worker to force fresh registration on next visit
|
||||
await self.registration.unregister();
|
||||
|
||||
console.log('Service Worker: Logout handled - caches cleared and unregistered');
|
||||
} catch (error) {
|
||||
console.error('Service Worker: Error during logout handling', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Service Worker: Loaded successfully');
|
||||
Reference in New Issue
Block a user