Skip to content

Commit 26c424a

Browse files
Antreesybackportbot[bot]
authored andcommitted
fix: wipe local storages on log out
Signed-off-by: Maksim Sukharev <[email protected]> [skip ci]
1 parent a1f7480 commit 26c424a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

core/src/utils/xhr-request.js

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

66
import { getCurrentUser } from '@nextcloud/auth'
77
import { generateUrl, getRootUrl } from '@nextcloud/router'
8+
import logger from '../logger.js'
89

910
/**
1011
*
@@ -51,6 +52,7 @@ async function checkLoginStatus() {
5152
const { status } = await window.fetch(generateUrl('/apps/files'))
5253
if (status === 401) {
5354
console.warn('User session was terminated, forwarding to login page.')
55+
await wipeBrowserStorages()
5456
window.location = generateUrl('/login?redirect_url={url}', {
5557
url: window.location.pathname + window.location.search + window.location.hash,
5658
})
@@ -62,6 +64,24 @@ async function checkLoginStatus() {
6264
}
6365
}
6466

67+
/**
68+
* Clear all Browser storages connected to current origin.
69+
* @returns {Promise<void>}
70+
*/
71+
export async function wipeBrowserStorages() {
72+
try {
73+
window.localStorage.clear()
74+
window.sessionStorage.clear()
75+
const indexedDBList = await window.indexedDB.databases()
76+
for (const indexedDB of indexedDBList) {
77+
await window.indexedDB.deleteDatabase(indexedDB.name)
78+
}
79+
logger.debug('Browser storages cleared')
80+
} catch (error) {
81+
logger.error('Could not clear browser storages', { error })
82+
}
83+
}
84+
6585
/**
6686
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
6787
*

core/src/views/Login.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,7 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
116116
117117
const query = queryString.parse(location.search)
118118
if (query.clear === '1') {
119-
try {
120-
window.localStorage.clear()
121-
window.sessionStorage.clear()
122-
console.debug('Browser storage cleared')
123-
} catch (e) {
124-
console.error('Could not clear browser storage', e)
125-
}
119+
wipeBrowserStorages()
126120
}
127121
128122
export default {

0 commit comments

Comments
 (0)