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 *
0 commit comments