Changeset View
Changeset View
Standalone View
Standalone View
web/database/sqlite-data-handler.js
Show All 21 Lines | function SQLiteDataHandler(): React.Node { | ||||
const handleSensitiveData = React.useCallback(async () => { | const handleSensitiveData = React.useCallback(async () => { | ||||
const databaseModule = await getDatabaseModule(); | const databaseModule = await getDatabaseModule(); | ||||
try { | try { | ||||
const currentUserData = await databaseModule.schedule({ | const currentUserData = await databaseModule.schedule({ | ||||
type: workerRequestMessageTypes.GET_CURRENT_USER_ID, | type: workerRequestMessageTypes.GET_CURRENT_USER_ID, | ||||
}); | }); | ||||
const currentDBUserID = currentUserData?.userID; | const currentDBUserID = currentUserData?.userID; | ||||
if (currentDBUserID && currentDBUserID !== currentLoggedInUserID) { | if (currentDBUserID === currentLoggedInUserID) { | ||||
await databaseModule.clearSensitiveData(); | return; | ||||
} | |||||
if (currentDBUserID) { | |||||
await databaseModule.init({ clearDatabase: true }); | |||||
} | } | ||||
if ( | if (currentLoggedInUserID) { | ||||
currentLoggedInUserID && | |||||
(currentDBUserID || currentDBUserID !== currentLoggedInUserID) | |||||
) { | |||||
await databaseModule.schedule({ | await databaseModule.schedule({ | ||||
type: workerRequestMessageTypes.SET_CURRENT_USER_ID, | type: workerRequestMessageTypes.SET_CURRENT_USER_ID, | ||||
userID: currentLoggedInUserID, | userID: currentLoggedInUserID, | ||||
}); | }); | ||||
} | } | ||||
} catch (error) { | } catch (error) { | ||||
console.error(error); | console.error(error); | ||||
throw error; | throw error; | ||||
} | } | ||||
}, [currentLoggedInUserID]); | }, [currentLoggedInUserID]); | ||||
React.useEffect(() => { | React.useEffect(() => { | ||||
(async () => { | (async () => { | ||||
const databaseModule = await getDatabaseModule(); | const databaseModule = await getDatabaseModule(); | ||||
if (currentLoggedInUserID) { | |||||
await databaseModule.init(currentLoggedInUserID); | |||||
} | |||||
if (!rehydrateConcluded) { | if (!rehydrateConcluded) { | ||||
return; | return; | ||||
} | } | ||||
const isSupported = await databaseModule.isDatabaseSupported(); | const isSupported = await databaseModule.isDatabaseSupported(); | ||||
if (!isSupported) { | if (!isSupported) { | ||||
return; | return; | ||||
} | } | ||||
Show All 33 Lines |