Skip to content

Commit c01461d

Browse files
committed
fix: wipe local storages on log out
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 662492b commit c01461d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,11 @@ import ResetPassword from '../components/login/ResetPassword.vue'
131131
import UpdatePassword from '../components/login/UpdatePassword.vue'
132132
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
133133
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
134+
import { wipeBrowserStorages } from '../utils/xhr-request.js'
134135
135136
const query = queryString.parse(location.search)
136137
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-
}
138+
wipeBrowserStorages()
144139
}
145140
146141
export default {

0 commit comments

Comments
 (0)