Skip to content

Commit e73bbbc

Browse files
Antreesybackportbot[bot]
authored andcommitted
fix: wipe local storages on log out
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com> [skip ci]
1 parent 77c9238 commit e73bbbc

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

core/src/utils/xhr-request.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import { getCurrentUser } from '@nextcloud/auth'
2323
import { generateUrl, getRootUrl } from '@nextcloud/router'
24+
import logger from '../logger.js'
2425

2526
/**
2627
*
@@ -67,6 +68,7 @@ async function checkLoginStatus() {
6768
const { status } = await window.fetch(generateUrl('/apps/files'))
6869
if (status === 401) {
6970
console.warn('User session was terminated, forwarding to login page.')
71+
await wipeBrowserStorages()
7072
window.location = generateUrl('/login?redirect_url={url}', {
7173
url: window.location.pathname + window.location.search + window.location.hash,
7274
})
@@ -78,6 +80,24 @@ async function checkLoginStatus() {
7880
}
7981
}
8082

83+
/**
84+
* Clear all Browser storages connected to current origin.
85+
* @returns {Promise<void>}
86+
*/
87+
export async function wipeBrowserStorages() {
88+
try {
89+
window.localStorage.clear()
90+
window.sessionStorage.clear()
91+
const indexedDBList = await window.indexedDB.databases()
92+
for (const indexedDB of indexedDBList) {
93+
await window.indexedDB.deleteDatabase(indexedDB.name)
94+
}
95+
logger.debug('Browser storages cleared')
96+
} catch (error) {
97+
logger.error('Could not clear browser storages', { error })
98+
}
99+
}
100+
81101
/**
82102
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
83103
*

core/src/views/Login.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,7 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
134134
135135
const query = queryString.parse(location.search)
136136
if (query.clear === '1') {
137-
try {
138-
window.localStorage.clear()
139-
window.sessionStorage.clear()
140-
console.debug('Browser storage cleared')
141-
} catch (e) {
142-
console.error('Could not clear browser storage', e)
143-
}
137+
wipeBrowserStorages()
144138
}
145139
146140
export default {

0 commit comments

Comments
 (0)