File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change 2121
2222import { getCurrentUser } from '@nextcloud/auth'
2323import { 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 *
Original file line number Diff line number Diff line change @@ -131,16 +131,11 @@ import ResetPassword from '../components/login/ResetPassword.vue'
131131import UpdatePassword from ' ../components/login/UpdatePassword.vue'
132132import NcButton from ' @nextcloud/vue/dist/Components/NcButton.js'
133133import NcNoteCard from ' @nextcloud/vue/dist/Components/NcNoteCard.js'
134+ import { wipeBrowserStorages } from ' ../utils/xhr-request.js'
134135
135136const query = queryString .parse (location .search )
136137if (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
146141export default {
You can’t perform that action at this time.
0 commit comments