Skip to content

Commit afd27f4

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

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
@@ -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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,11 @@ import ResetPassword from '../components/login/ResetPassword.vue'
113113
import UpdatePassword from '../components/login/UpdatePassword.vue'
114114
import NcButton from '@nextcloud/vue/components/NcButton'
115115
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
116+
import { wipeBrowserStorages } from '../utils/xhr-request.js'
116117
117118
const query = queryString.parse(location.search)
118119
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-
}
120+
wipeBrowserStorages()
126121
}
127122
128123
export default {

0 commit comments

Comments
 (0)