From 1ea3d005e8606df8ab3766c6fd496e1990eb4654 Mon Sep 17 00:00:00 2001 From: certuna <62144283+certuna@users.noreply.github.com> Date: Sun, 21 Mar 2021 19:34:10 +0100 Subject: [PATCH] clear the ServiceWorker cache on logout (#854) * Update authProvider.js This fixes https://github.com/navidrome/navidrome/issues/613 : clears the ServiceWorker cache on logout. Based on this code: https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage/keys . Seems to work on macOS and iOS, but please test on other platforms. * Format code with `prettier` Co-authored-by: Deluan --- ui/src/authProvider.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ui/src/authProvider.js b/ui/src/authProvider.js index 54edada51..e64798cad 100644 --- a/ui/src/authProvider.js +++ b/ui/src/authProvider.js @@ -59,6 +59,7 @@ const authProvider = { logout: () => { stopEventStream() removeItems() + clearServiceWorkerCache() return Promise.resolve() }, @@ -97,6 +98,12 @@ const removeItems = () => { localStorage.removeItem('subsonic-token') } +const clearServiceWorkerCache = () => { + caches.keys().then(function (keyList) { + for (let key of keyList) caches.delete(key) + }) +} + const generateSubsonicSalt = () => { const h = md5(uuidv4()) return h.slice(0, 6)