aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/utils/xhr-request.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/utils/xhr-request.js')
-rw-r--r--core/src/utils/xhr-request.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/src/utils/xhr-request.js b/core/src/utils/xhr-request.js
index 68641ebc006..c256313df31 100644
--- a/core/src/utils/xhr-request.js
+++ b/core/src/utils/xhr-request.js
@@ -5,6 +5,7 @@
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl, getRootUrl } from '@nextcloud/router'
+import logger from '../logger.js'
/**
*
@@ -51,6 +52,7 @@ async function checkLoginStatus() {
const { status } = await window.fetch(generateUrl('/apps/files'))
if (status === 401) {
console.warn('User session was terminated, forwarding to login page.')
+ await wipeBrowserStorages()
window.location = generateUrl('/login?redirect_url={url}', {
url: window.location.pathname + window.location.search + window.location.hash,
})
@@ -63,6 +65,24 @@ async function checkLoginStatus() {
}
/**
+ * Clear all Browser storages connected to current origin.
+ * @returns {Promise<void>}
+ */
+export async function wipeBrowserStorages() {
+ try {
+ window.localStorage.clear()
+ window.sessionStorage.clear()
+ const indexedDBList = await window.indexedDB.databases()
+ for (const indexedDB of indexedDBList) {
+ await window.indexedDB.deleteDatabase(indexedDB.name)
+ }
+ logger.debug('Browser storages cleared')
+ } catch (error) {
+ logger.error('Could not clear browser storages', { error })
+ }
+}
+
+/**
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
*
* This is also done in @nextcloud/axios but not all requests pass through that