@@ -33,7 +33,7 @@ const isNextcloudUrl = (url) => {
3333 * @returns {Promise<void> }
3434 */
3535async function checkLoginStatus ( ) {
36- // skip if no logged- in user
36+ // skip if no logged in user
3737 if ( getCurrentUser ( ) === null ) {
3838 return
3939 }
@@ -51,13 +51,7 @@ async function checkLoginStatus() {
5151 const { status } = await window . fetch ( generateUrl ( '/apps/files' ) )
5252 if ( status === 401 ) {
5353 console . warn ( 'User session was terminated, forwarding to login page.' )
54- // Clear all storages and redirect to login page
55- window . localStorage . clear ( )
56- window . sessionStorage . clear ( )
57- const indexedDBList = await window . indexedDB . databases ( )
58- for ( const indexedDB of indexedDBList ) {
59- await window . indexedDB . deleteDatabase ( indexedDB . name )
60- }
54+ await wipeBrowserStorages ( )
6155 window . location = generateUrl ( '/login?redirect_url={url}' , {
6256 url : window . location . pathname + window . location . search + window . location . hash ,
6357 } )
@@ -69,6 +63,24 @@ async function checkLoginStatus() {
6963 }
7064}
7165
66+ /**
67+ * Clear all Browser storages connected to current origin.
68+ * @returns {Promise<void> }
69+ */
70+ export async function wipeBrowserStorages ( ) {
71+ try {
72+ window . localStorage . clear ( )
73+ window . sessionStorage . clear ( )
74+ const indexedDBList = await window . indexedDB . databases ( )
75+ for ( const indexedDB of indexedDBList ) {
76+ await window . indexedDB . deleteDatabase ( indexedDB . name )
77+ }
78+ console . debug ( 'Browser storages cleared' )
79+ } catch ( e ) {
80+ console . error ( 'Could not clear browser storages' , e )
81+ }
82+ }
83+
7284/**
7385 * Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
7486 *
0 commit comments