diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -39,7 +39,16 @@ import { useStaffCanSee } from '../utils/staff-utils.js'; async function clearSensitiveData() { - await commCoreModule.clearSensitiveData(); + try { + await commCoreModule.clearSensitiveData(); + } catch (error) { + console.log( + `Error clearing SQLite database: ${ + getMessageForException(error) ?? 'unknown' + }`, + ); + throw error; + } try { await filesystemMediaCache.clearCache(); } catch { @@ -139,11 +148,28 @@ const handleSensitiveData = React.useCallback(async () => { try { - const sqliteStampedUserID = await commCoreModule.getSQLiteStampedUserID(); - if (shouldClearData(sqliteStampedUserID, currentLoggedInUserID)) { + let sqliteStampedUserID, + errorGettingStampedUserID = false; + try { + sqliteStampedUserID = await commCoreModule.getSQLiteStampedUserID(); + } catch (error) { + errorGettingStampedUserID = true; + console.log( + `Error getting SQLite stamped user ID: ${ + getMessageForException(error) ?? 'unknown' + }`, + ); + } + if ( + errorGettingStampedUserID || + shouldClearData(sqliteStampedUserID, currentLoggedInUserID) + ) { await callClearSensitiveData('change in logged-in user credentials'); } - if (currentLoggedInUserID) { + if ( + currentLoggedInUserID && + currentLoggedInUserID !== sqliteStampedUserID + ) { await commCoreModule.stampSQLiteDBUserID(currentLoggedInUserID); } } catch (e) { diff --git a/web/shared-worker/sqlite-data-handler.js b/web/shared-worker/sqlite-data-handler.js --- a/web/shared-worker/sqlite-data-handler.js +++ b/web/shared-worker/sqlite-data-handler.js @@ -21,25 +21,25 @@ const handleSensitiveData = React.useCallback(async () => { const sharedWorker = await getCommSharedWorker(); - let currentDBUserID, - errorGettingUserID = false; + let sqliteStampedUserID, + errorGettingStampedUserID = false; try { const currentUserData = await sharedWorker.schedule({ type: workerRequestMessageTypes.GET_SQLITE_STAMPED_USER_ID, }); - currentDBUserID = currentUserData?.userID; + sqliteStampedUserID = currentUserData?.userID; } catch (error) { - errorGettingUserID = true; + errorGettingStampedUserID = true; console.error( - `Error setting current user ID: ${ + `Error getting SQLite stamped user ID: ${ getMessageForException(error) ?? 'unknown' }`, ); } if ( - errorGettingUserID || - shouldClearData(currentDBUserID, currentLoggedInUserID) + errorGettingStampedUserID || + shouldClearData(sqliteStampedUserID, currentLoggedInUserID) ) { try { await sharedWorker.init({ clearDatabase: true }); @@ -54,7 +54,10 @@ } } - if (currentLoggedInUserID && currentLoggedInUserID !== currentDBUserID) { + if ( + currentLoggedInUserID && + currentLoggedInUserID !== sqliteStampedUserID + ) { try { await sharedWorker.schedule({ type: workerRequestMessageTypes.STAMP_SQLITE_DB_USER_ID, @@ -62,7 +65,7 @@ }); } catch (error) { console.error( - `Error setting current user ID: ${ + `Error stamping SQLite database with user ID: ${ getMessageForException(error) ?? 'unknown' }`, );