Skip to content

Commit 745bcaf

Browse files
committed
fixup!: fix: wipe local storages on log out
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 0fdc214 commit 745bcaf

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

core/src/utils/xhr-request.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const isNextcloudUrl = (url) => {
3333
* @returns {Promise<void>}
3434
*/
3535
async function checkLoginStatus() {
36-
// skip if no logged-in user
36+
// skip if no logged in user
3737
if (getCurrentUser() === null) {
3838
return
3939
}
@@ -51,13 +51,7 @@ async function checkLoginStatus() {
5151
const { status } = await window.fetch(generateUrl('/apps/files'))
5252
if (status === 401) {
5353
console.warn('User session was terminated, forwarding to login page.')
54-
// Clear all storages and redirect to login page
55-
window.localStorage.clear()
56-
window.sessionStorage.clear()
57-
const indexedDBList = await window.indexedDB.databases()
58-
for (const indexedDB of indexedDBList) {
59-
await window.indexedDB.deleteDatabase(indexedDB.name)
60-
}
54+
await wipeBrowserStorages()
6155
window.location = generateUrl('/login?redirect_url={url}', {
6256
url: window.location.pathname + window.location.search + window.location.hash,
6357
})
@@ -69,6 +63,24 @@ async function checkLoginStatus() {
6963
}
7064
}
7165

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

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)