Skip to content

Commit

Permalink
fixup!: fix: wipe local storages on log out
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Feb 21, 2025
1 parent 0fdc214 commit 745bcaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 20 additions & 8 deletions core/src/utils/xhr-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const isNextcloudUrl = (url) => {
* @returns {Promise<void>}
*/
async function checkLoginStatus() {
// skip if no logged-in user
// skip if no logged in user
if (getCurrentUser() === null) {
return
}
Expand All @@ -51,13 +51,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.')
// Clear all storages and redirect to login page
window.localStorage.clear()
window.sessionStorage.clear()
const indexedDBList = await window.indexedDB.databases()
for (const indexedDB of indexedDBList) {
await window.indexedDB.deleteDatabase(indexedDB.name)
}
await wipeBrowserStorages()
window.location = generateUrl('/login?redirect_url={url}', {
url: window.location.pathname + window.location.search + window.location.hash,
})
Expand All @@ -69,6 +63,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)
}
console.debug('Browser storages cleared')
} catch (e) {
console.error('Could not clear browser storages', e)
}
}

/**
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
*
Expand Down
9 changes: 2 additions & 7 deletions core/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 745bcaf

Please sign in to comment.