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 55
66import { getCurrentUser } from '@nextcloud/auth'
77import { 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 *
Original file line number Diff line number Diff line change @@ -113,16 +113,11 @@ import ResetPassword from '../components/login/ResetPassword.vue'
113113import UpdatePassword from ' ../components/login/UpdatePassword.vue'
114114import NcButton from ' @nextcloud/vue/components/NcButton'
115115import NcNoteCard from ' @nextcloud/vue/components/NcNoteCard'
116+ import { wipeBrowserStorages } from ' ../utils/xhr-request.js'
116117
117118const query = queryString .parse (location .search )
118119if (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
128123export default {
You can’t perform that action at this time.
0 commit comments