diff --git a/native/data/sensitive-data-handler.react.js b/native/data/sensitive-data-handler.react.js
deleted file mode 100644
--- a/native/data/sensitive-data-handler.react.js
+++ /dev/null
@@ -1,43 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import ExitApp from 'react-native-exit-app';
-
-import { commCoreModule } from '../native-modules';
-import { useSelector } from '../redux/redux-utils';
-
-function SensitiveDataHandler(): null {
- const currentLoggedInUserID: ?string = useSelector(state =>
- state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id,
- );
- React.useEffect(() => {
- (async () => {
- try {
- const databaseCurrentUserInfoID = await commCoreModule.getCurrentUserID();
- if (
- databaseCurrentUserInfoID &&
- databaseCurrentUserInfoID !== currentLoggedInUserID
- ) {
- await commCoreModule.clearSensitiveData();
- }
- if (currentLoggedInUserID) {
- await commCoreModule.setCurrentUserID(currentLoggedInUserID);
- }
- const databaseDeviceID = await commCoreModule.getDeviceID();
- if (!databaseDeviceID) {
- await commCoreModule.setDeviceID('MOBILE');
- }
- } catch (e) {
- if (__DEV__) {
- throw e;
- } else {
- console.log(e);
- ExitApp.exitApp();
- }
- }
- })();
- }, [currentLoggedInUserID]);
- return null;
-}
-
-export { SensitiveDataHandler };
diff --git a/native/data/sqlite-context-provider.js b/native/data/sqlite-context-provider.js
--- a/native/data/sqlite-context-provider.js
+++ b/native/data/sqlite-context-provider.js
@@ -33,9 +33,42 @@
const urlPrefix = useSelector(state => state.urlPrefix);
const staffCanSee = useStaffCanSee();
const loggedIn = useSelector(isLoggedIn);
+ const currentLoggedInUserID = useSelector(state =>
+ state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id,
+ );
+
+ const handleSensitiveData = React.useCallback(async () => {
+ try {
+ const databaseCurrentUserInfoID = await commCoreModule.getCurrentUserID();
+ if (
+ databaseCurrentUserInfoID &&
+ databaseCurrentUserInfoID !== currentLoggedInUserID
+ ) {
+ await commCoreModule.clearSensitiveData();
+ }
+ if (currentLoggedInUserID) {
+ await commCoreModule.setCurrentUserID(currentLoggedInUserID);
+ }
+ const databaseDeviceID = await commCoreModule.getDeviceID();
+ if (!databaseDeviceID) {
+ await commCoreModule.setDeviceID('MOBILE');
+ }
+ } catch (e) {
+ if (__DEV__) {
+ throw e;
+ } else {
+ console.log(e);
+ ExitApp.exitApp();
+ }
+ }
+ }, [currentLoggedInUserID]);
React.useEffect(() => {
- if (storeLoaded || !rehydrateConcluded) {
+ if (!rehydrateConcluded) {
+ return;
+ }
+ const sensitiveDataHandled = handleSensitiveData();
+ if (storeLoaded) {
return;
}
if (!loggedIn) {
@@ -43,6 +76,7 @@
return;
}
(async () => {
+ await sensitiveDataHandled;
try {
const [threads, messages] = await Promise.all([
commCoreModule.getAllThreads(),
@@ -92,6 +126,7 @@
}
})();
}, [
+ handleSensitiveData,
loggedIn,
cookie,
dispatch,
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -23,7 +23,6 @@
import PersistedStateGate from './components/persisted-state-gate';
import ConnectedStatusBar from './connected-status-bar.react';
import CoreDataProvider from './data/core-data-provider.react';
-import { SensitiveDataHandler } from './data/sensitive-data-handler.react';
import { SQLiteContextProvider } from './data/sqlite-context-provider';
import ErrorBoundary from './error-boundary.react';
import InputStateContainer from './input/input-state-container.react';
@@ -225,7 +224,6 @@
-
>
);
let navigation;