diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -320,6 +320,8 @@ return { updates }; }; +const resetUserStateActionType = 'RESET_USER_STATE'; + export { changeUserPasswordActionTypes, changeUserPassword, @@ -347,4 +349,5 @@ policyAcknowledgmentActionTypes, updateUserAvatarActionTypes, updateUserAvatar, + resetUserStateActionType, }; diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -15,6 +15,7 @@ registerActionTypes, setUserSettingsActionTypes, updateUserAvatarActionTypes, + resetUserStateActionType, } from '../actions/user-actions.js'; import type { BaseAction } from '../types/redux-types.js'; import { @@ -121,6 +122,8 @@ }, }; } + } else if (action.type === resetUserStateActionType) { + state = state && state.anonymous ? state : null; } return state; } diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -1167,7 +1167,8 @@ | { +type: 'UPDATE_LAST_COMMUNICATED_PLATFORM_DETAILS', +payload: LastCommunicatedPlatformDetails, - }; + } + | { +type: 'RESET_USER_STATE', +payload?: void }; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string); export type SuperAction = { diff --git a/native/account/logged-out-modal.react.js b/native/account/logged-out-modal.react.js --- a/native/account/logged-out-modal.react.js +++ b/native/account/logged-out-modal.react.js @@ -17,6 +17,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import { useDispatch } from 'react-redux'; +import { resetUserStateActionType } from 'lib/actions/user-actions.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import { logInActionSources } from 'lib/types/account-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; @@ -44,7 +45,6 @@ LoggedOutModalRouteName, RegistrationRouteName, } from '../navigation/route-names.js'; -import { resetUserStateActionType } from '../redux/action-types.js'; import { useSelector } from '../redux/redux-utils.js'; import { usePersistedStateLoaded } from '../selectors/app-state-selectors.js'; import { diff --git a/native/redux/action-types.js b/native/redux/action-types.js --- a/native/redux/action-types.js +++ b/native/redux/action-types.js @@ -12,7 +12,6 @@ import type { ConnectivityInfo } from '../types/connectivity.js'; import type { GlobalThemeInfo } from '../types/themes.js'; -export const resetUserStateActionType = 'RESET_USER_STATE'; export const updateDimensionsActiveType = 'UPDATE_DIMENSIONS'; export const updateConnectivityActiveType = 'UPDATE_CONNECTIVITY'; export const updateThemeInfoActionType = 'UPDATE_THEME_INFO'; @@ -37,7 +36,6 @@ +type: 'SET_CUSTOM_SERVER', +payload: string, } - | { +type: 'RESET_USER_STATE' } | { +type: 'UPDATE_DIMENSIONS', +payload: Shape, diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -12,6 +12,7 @@ logOutActionTypes, deleteAccountActionTypes, logInActionTypes, + resetUserStateActionType, } from 'lib/actions/user-actions.js'; import baseReducer from 'lib/reducers/master-reducer.js'; import { processThreadStoreOperations } from 'lib/reducers/thread-reducer.js'; @@ -32,7 +33,6 @@ import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; import { - resetUserStateActionType, updateDimensionsActiveType, updateConnectivityActiveType, updateThemeInfoActionType, @@ -228,20 +228,6 @@ ...state, customServer: action.payload, }; - } else if (action.type === resetUserStateActionType) { - const cookie = - state.cookie && state.cookie.startsWith('anonymous=') - ? state.cookie - : null; - const currentUserInfo = - state.currentUserInfo && state.currentUserInfo.anonymous - ? state.currentUserInfo - : null; - return { - ...state, - currentUserInfo, - cookie, - }; } else if (action.type === updateDimensionsActiveType) { return { ...state, @@ -342,6 +328,16 @@ return state; } } + if (action.type === resetUserStateActionType) { + const cookie = + state.cookie && state.cookie.startsWith('anonymous=') + ? state.cookie + : null; + state = { + ...state, + cookie, + }; + } const baseReducerResult = baseReducer(state, (action: BaseAction)); state = baseReducerResult.state;