diff --git a/native/components/background-identity-login-handler.react.js b/native/components/background-identity-login-handler.react.js new file mode 100644 --- /dev/null +++ b/native/components/background-identity-login-handler.react.js @@ -0,0 +1,48 @@ +// @flow + +import * as React from 'react'; + +import { logOutActionTypes, useLogOut } from 'lib/actions/user-actions.js'; +import { useModalContext } from 'lib/components/modal-provider.react.js'; +import { accountHasPassword } from 'lib/shared/account-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; +import { useSelector } from 'lib/utils/redux-utils.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; + +import Alert from '../utils/alert.js'; + +function BackgroundIdentityLoginHandler() { + const dispatchActionPromise = useDispatchActionPromise(); + const callLogOut = useLogOut(); + + const isAccountWithPassword = useSelector(state => + accountHasPassword(state.currentUserInfo), + ); + const hasAccessToken = useSelector(state => !!state.commServicesAccessToken); + const dataLoaded = useSelector(state => state.dataLoaded); + + const { pushModal } = useModalContext(); + + React.useEffect(() => { + if (hasAccessToken || !dataLoaded || !usingCommServicesAccessToken) { + return; + } + if (!isAccountWithPassword) { + void dispatchActionPromise(logOutActionTypes, callLogOut()); + Alert.alert( + 'Security update', + 'Unfortunately, we must log you out as we perform an update to our system.', + [{ text: 'OK' }], + ); + } + }, [ + callLogOut, + dataLoaded, + dispatchActionPromise, + hasAccessToken, + isAccountWithPassword, + pushModal, + ]); +} + +export default BackgroundIdentityLoginHandler; diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -46,6 +46,7 @@ import ChatContextProvider from './chat/chat-context-provider.react.js'; import MessageEditingContextProvider from './chat/message-editing-context-provider.react.js'; import AccessTokenHandler from './components/access-token-handler.react.js'; +import BackgroundIdentityLoginHandler from './components/background-identity-login-handler.react.js'; import ConnectFarcasterAlertHandler from './components/connect-farcaster-alert-handler.react.js'; import { FeatureFlagsProvider } from './components/feature-flags-provider.react.js'; import PersistedStateGate from './components/persisted-state-gate.js'; @@ -342,6 +343,7 @@ } /> +