diff --git a/lib/types/alert-types.js b/lib/types/alert-types.js --- a/lib/types/alert-types.js +++ b/lib/types/alert-types.js @@ -37,4 +37,12 @@ [alertTypes.SIWE_BACKUP_MESSAGE]: defaultAlertInfo, }); -export { alertTypes, defaultAlertInfo, defaultAlertInfos }; +const securityUpdateLogoutText: string = + 'Unfortunately, we must log you out as we perform an update to our system.'; + +export { + alertTypes, + defaultAlertInfo, + defaultAlertInfos, + securityUpdateLogoutText, +}; 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,47 @@ +// @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 { securityUpdateLogoutText } from 'lib/types/alert-types.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', securityUpdateLogoutText, [ + { 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'; @@ -337,6 +338,7 @@ } /> + diff --git a/web/components/log-out-if-missing-csat-handler.react.js b/web/components/log-out-if-missing-csat-handler.react.js --- a/web/components/log-out-if-missing-csat-handler.react.js +++ b/web/components/log-out-if-missing-csat-handler.react.js @@ -5,6 +5,7 @@ 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 { securityUpdateLogoutText } from 'lib/types/alert-types.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'; @@ -37,12 +38,7 @@

); } else { - modalContent = ( -

- Unfortunately, we must log you out as we perform an update to our - system. -

- ); + modalContent =

{securityUpdateLogoutText}

; } return (