diff --git a/lib/shared/session-utils.js b/lib/shared/session-utils.js --- a/lib/shared/session-utils.js +++ b/lib/shared/session-utils.js @@ -11,12 +11,12 @@ import type { AppState } from '../types/redux-types.js'; import type { PreRequestUserState } from '../types/session-types.js'; import type { CurrentUserInfo } from '../types/user-types.js'; -import { ashoatKeyserverID } from '../utils/validation-utils.js'; function invalidSessionDowngrade( currentReduxState: AppState, actionCurrentUserInfo: ?CurrentUserInfo, preRequestUserState: ?PreRequestUserState, + keyserverID: string, ): boolean { // If this action represents a session downgrade - oldState has a loggedIn // currentUserInfo, but the action has an anonymous one - then it is only @@ -35,10 +35,10 @@ (actionCurrentUserInfo && actionCurrentUserInfo.anonymous)) && preRequestUserState && (preRequestUserState.currentUserInfo?.id !== currentCurrentUserInfo.id || - preRequestUserState.cookiesAndSessions[ashoatKeyserverID].cookie !== - cookieSelector(ashoatKeyserverID)(currentReduxState) || - preRequestUserState.cookiesAndSessions[ashoatKeyserverID].sessionID !== - sessionIDSelector(ashoatKeyserverID)(currentReduxState)) + preRequestUserState.cookiesAndSessions[keyserverID].cookie !== + cookieSelector(keyserverID)(currentReduxState) || + preRequestUserState.cookiesAndSessions[keyserverID].sessionID !== + sessionIDSelector(keyserverID)(currentReduxState)) ); } 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 @@ -25,6 +25,7 @@ import type { SetSessionPayload } from 'lib/types/session-types.js'; import { reduxLoggerMiddleware } from 'lib/utils/action-logger.js'; import { setNewSessionActionType } from 'lib/utils/action-utils.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { updateDimensionsActiveType, @@ -110,18 +111,21 @@ state, action.payload.sessionChange.currentUserInfo, action.payload.preRequestUserState, + action.payload.keyserverID, )) || (action.type === logOutActionTypes.success && invalidSessionDowngrade( state, action.payload.currentUserInfo, action.payload.preRequestUserState, + ashoatKeyserverID, )) || (action.type === deleteAccountActionTypes.success && invalidSessionDowngrade( state, action.payload.currentUserInfo, action.payload.preRequestUserState, + ashoatKeyserverID, )) ) { return state; diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -162,11 +162,14 @@ storeOperations, ); } else if (action.type === setNewSessionActionType) { + const { keyserverID } = action.payload; + if ( invalidSessionDowngrade( oldState, action.payload.sessionChange.currentUserInfo, action.payload.preRequestUserState, + keyserverID, ) ) { return oldState; @@ -178,8 +181,8 @@ ...state.keyserverStore, keyserverInfos: { ...state.keyserverStore.keyserverInfos, - [ashoatKeyserverID]: { - ...state.keyserverStore.keyserverInfos[ashoatKeyserverID], + [keyserverID]: { + ...state.keyserverStore.keyserverInfos[keyserverID], sessionID: action.payload.sessionChange.sessionID, }, }, @@ -191,12 +194,14 @@ oldState, action.payload.currentUserInfo, action.payload.preRequestUserState, + ashoatKeyserverID, )) || (action.type === deleteAccountActionTypes.success && invalidSessionDowngrade( oldState, action.payload.currentUserInfo, action.payload.preRequestUserState, + ashoatKeyserverID, )) ) { return oldState;