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