mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
fix: wipe local storages on log out
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
This commit is contained in:
parent
c1204c0670
commit
afd27f4bc4
2 changed files with 22 additions and 7 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
import { generateUrl, getRootUrl } from '@nextcloud/router'
|
||||
import logger from '../logger.js'
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -51,6 +52,7 @@ async function checkLoginStatus() {
|
|||
const { status } = await window.fetch(generateUrl('/apps/files'))
|
||||
if (status === 401) {
|
||||
console.warn('User session was terminated, forwarding to login page.')
|
||||
await wipeBrowserStorages()
|
||||
window.location = generateUrl('/login?redirect_url={url}', {
|
||||
url: window.location.pathname + window.location.search + window.location.hash,
|
||||
})
|
||||
|
|
@ -62,6 +64,24 @@ async function checkLoginStatus() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all Browser storages connected to current origin.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function wipeBrowserStorages() {
|
||||
try {
|
||||
window.localStorage.clear()
|
||||
window.sessionStorage.clear()
|
||||
const indexedDBList = await window.indexedDB.databases()
|
||||
for (const indexedDB of indexedDBList) {
|
||||
await window.indexedDB.deleteDatabase(indexedDB.name)
|
||||
}
|
||||
logger.debug('Browser storages cleared')
|
||||
} catch (error) {
|
||||
logger.error('Could not clear browser storages', { error })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
|
||||
*
|
||||
|
|
|
|||
|
|
@ -113,16 +113,11 @@ import ResetPassword from '../components/login/ResetPassword.vue'
|
|||
import UpdatePassword from '../components/login/UpdatePassword.vue'
|
||||
import NcButton from '@nextcloud/vue/components/NcButton'
|
||||
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
|
||||
import { wipeBrowserStorages } from '../utils/xhr-request.js'
|
||||
|
||||
const query = queryString.parse(location.search)
|
||||
if (query.clear === '1') {
|
||||
try {
|
||||
window.localStorage.clear()
|
||||
window.sessionStorage.clear()
|
||||
console.debug('Browser storage cleared')
|
||||
} catch (e) {
|
||||
console.error('Could not clear browser storage', e)
|
||||
}
|
||||
wipeBrowserStorages()
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
Loading…
Reference in a new issue