diff --git a/ui/src/authProvider.js b/ui/src/authProvider.js index 588523813..4ae238eec 100644 --- a/ui/src/authProvider.js +++ b/ui/src/authProvider.js @@ -1,6 +1,7 @@ import { jwtDecode } from 'jwt-decode' import { baseUrl } from './utils' import config from './config' +import { removeHomeCache } from './utils/removeHomeCache' // config sent from server may contain authentication info, for example when the user is authenticated // by a reverse proxy request header @@ -48,6 +49,7 @@ const authProvider = { storeAuthenticationInfo(response) // Avoid "going to create admin" dialog after logout/login without a refresh config.firstTime = false + removeHomeCache() return response }) .catch((error) => { diff --git a/ui/src/dataProvider/httpClient.js b/ui/src/dataProvider/httpClient.js index 5ade3c0ce..a8897aef8 100644 --- a/ui/src/dataProvider/httpClient.js +++ b/ui/src/dataProvider/httpClient.js @@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid' import { baseUrl } from '../utils' import config from '../config' import { jwtDecode } from 'jwt-decode' +import { removeHomeCache } from '../utils/removeHomeCache' const customAuthorizationHeader = 'X-ND-Authorization' const clientUniqueIdHeader = 'X-ND-Client-Unique-Id' @@ -26,6 +27,7 @@ const httpClient = (url, options = {}) => { localStorage.setItem('userId', decoded.uid) // Avoid going to create admin dialog after logout/login without a refresh config.firstTime = false + removeHomeCache() } return response }) diff --git a/ui/src/utils/removeHomeCache.js b/ui/src/utils/removeHomeCache.js new file mode 100644 index 000000000..08ed720e0 --- /dev/null +++ b/ui/src/utils/removeHomeCache.js @@ -0,0 +1,20 @@ +export const removeHomeCache = async () => { + try { + const workboxKey = (await caches.keys()).find((key) => + key.startsWith('workbox-precache'), + ) + if (!workboxKey) return + + const workboxCache = await caches.open(workboxKey) + const indexKey = (await workboxCache.keys()).find((key) => + key.url.includes('app/index.html'), + ) + + if (indexKey) { + await workboxCache.delete(indexKey) + } + } catch (e) { + // eslint-disable-next-line no-console + console.error('error reading cache', e) + } +}