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 @@ -105,16 +105,6 @@ return flattened; } -const cookieInvalidationResolutionAttempt = - 'COOKIE_INVALIDATION_RESOLUTION_ATTEMPT'; -const appStartCookieLoggedInButInvalidRedux = - 'APP_START_COOKIE_LOGGED_IN_BUT_INVALID_REDUX'; -const appStartReduxLoggedInButInvalidCookie = - 'APP_START_REDUX_LOGGED_IN_BUT_INVALID_COOKIE'; -const socketAuthErrorResolutionAttempt = 'SOCKET_AUTH_ERROR_RESOLUTION_ATTEMPT'; -const sqliteOpFailure = 'SQLITE_OP_FAILURE'; -const sqliteLoadFailure = 'SQLITE_LOAD_FAILURE'; - const logInActionTypes = Object.freeze({ started: 'LOG_IN_STARTED', success: 'LOG_IN_SUCCESS', @@ -230,11 +220,8 @@ }; export { - appStartCookieLoggedInButInvalidRedux, - appStartReduxLoggedInButInvalidCookie, changeUserPasswordActionTypes, changeUserPassword, - cookieInvalidationResolutionAttempt, deleteAccount, deleteAccountActionTypes, getSessionPublicKeys, @@ -248,9 +235,6 @@ searchUsersActionTypes, setUserSettings, setUserSettingsActionTypes, - socketAuthErrorResolutionAttempt, - sqliteLoadFailure, - sqliteOpFailure, updateSubscription, updateSubscriptionActionTypes, }; diff --git a/lib/shared/account-utils.js b/lib/shared/account-utils.js --- a/lib/shared/account-utils.js +++ b/lib/shared/account-utils.js @@ -1,10 +1,9 @@ // @flow import { - cookieInvalidationResolutionAttempt, - socketAuthErrorResolutionAttempt, -} from '../actions/user-actions'; -import type { LogInActionSource } from '../types/account-types'; + loginActionSources, + type LogInActionSourceType, +} from '../types/account-types'; import type { AppState } from '../types/redux-types'; import type { PreRequestUserState } from '../types/session-types'; import type { CurrentUserInfo } from '../types/user-types'; @@ -60,11 +59,11 @@ function invalidSessionRecovery( currentReduxState: AppState, actionCurrentUserInfo: CurrentUserInfo, - source: ?LogInActionSource, + source: ?LogInActionSourceType, ): boolean { if ( - source !== cookieInvalidationResolutionAttempt && - source !== socketAuthErrorResolutionAttempt + source !== loginActionSources.cookieInvalidationResolutionAttempt && + source !== loginActionSources.socketAuthErrorResolutionAttempt ) { return false; } diff --git a/lib/socket/socket.react.js b/lib/socket/socket.react.js --- a/lib/socket/socket.react.js +++ b/lib/socket/socket.react.js @@ -5,10 +5,7 @@ import * as React from 'react'; import { updateActivityActionTypes } from '../actions/activity-actions'; -import { - socketAuthErrorResolutionAttempt, - logOutActionTypes, -} from '../actions/user-actions'; +import { logOutActionTypes } from '../actions/user-actions'; import { unsupervisedBackgroundActionType } from '../reducers/lifecycle-state-reducer'; import { pingFrequency, @@ -16,7 +13,7 @@ clientRequestVisualTimeout, clientRequestSocketTimeout, } from '../shared/timeouts'; -import type { LogOutResult } from '../types/account-types'; +import { loginActionSources, type LogOutResult } from '../types/account-types'; import type { CalendarQuery } from '../types/entry-types'; import type { Dispatch } from '../types/redux-types'; import { @@ -454,7 +451,7 @@ this.props.dispatch, cookie, this.props.urlPrefix, - socketAuthErrorResolutionAttempt, + loginActionSources.socketAuthErrorResolutionAttempt, ); if (!recoverySessionChange && sessionChange) { @@ -471,7 +468,7 @@ }, preRequestUserState: this.initializedWithUserState, error: null, - source: socketAuthErrorResolutionAttempt, + source: loginActionSources.socketAuthErrorResolutionAttempt, }, }); } else if (!recoverySessionChange) { diff --git a/lib/types/account-types.js b/lib/types/account-types.js --- a/lib/types/account-types.js +++ b/lib/types/account-types.js @@ -74,17 +74,22 @@ +password: string, }; -export type LogInActionSource = - | 'COOKIE_INVALIDATION_RESOLUTION_ATTEMPT' - | 'APP_START_COOKIE_LOGGED_IN_BUT_INVALID_REDUX' - | 'APP_START_REDUX_LOGGED_IN_BUT_INVALID_COOKIE' - | 'SOCKET_AUTH_ERROR_RESOLUTION_ATTEMPT' - | 'SQLITE_OP_FAILURE' - | 'SQLITE_LOAD_FAILURE'; +export const loginActionSources = Object.freeze({ + cookieInvalidationResolutionAttempt: 'COOKIE_INVALIDATION_RESOLUTION_ATTEMPT', + appStartCookieLoggedInButInvalidRedux: + 'APP_START_COOKIE_LOGGED_IN_BUT_INVALID_REDUX', + appStartReduxLoggedInButInvalidCookie: + 'APP_START_REDUX_LOGGED_IN_BUT_INVALID_COOKIE', + socketAuthErrorResolutionAttempt: 'SOCKET_AUTH_ERROR_RESOLUTION_ATTEMPT', + sqliteOpFailure: 'SQLITE_OP_FAILURE', + sqliteLoadFailure: 'SQLITE_LOAD_FAILURE', +}); + +export type LogInActionSourceType = $Values; export type LogInStartingPayload = { +calendarQuery: CalendarQuery, - +source?: LogInActionSource, + +source?: LogInActionSourceType, }; export type LogInExtraInfo = { @@ -96,7 +101,7 @@ ...LogInExtraInfo, +username: string, +password: string, - +source?: ?LogInActionSource, + +source?: ?LogInActionSourceType, }; export type LogInRequest = { @@ -129,7 +134,7 @@ +userInfos: $ReadOnlyArray, +calendarResult: CalendarResult, +updatesCurrentAsOf: number, - +source?: ?LogInActionSource, + +source?: ?LogInActionSourceType, }; export type UpdatePasswordRequest = { diff --git a/lib/types/session-types.js b/lib/types/session-types.js --- a/lib/types/session-types.js +++ b/lib/types/session-types.js @@ -1,6 +1,6 @@ // @flow -import type { LogInActionSource } from './account-types'; +import type { LogInActionSourceType } from './account-types'; import type { Shape } from './core'; import type { CalendarQuery } from './entry-types'; import type { RawThreadInfo } from './thread-types'; @@ -88,7 +88,7 @@ sessionChange: ClientSessionChange, preRequestUserState: ?PreRequestUserState, error: ?string, - source: ?LogInActionSource, + source: ?LogInActionSourceType, }; export type SessionState = { diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js --- a/lib/utils/action-utils.js +++ b/lib/utils/action-utils.js @@ -5,12 +5,12 @@ import { useSelector, useDispatch } from 'react-redux'; import { createSelector } from 'reselect'; -import { cookieInvalidationResolutionAttempt } from '../actions/user-actions'; import { serverCallStateSelector } from '../selectors/server-calls'; -import type { - LogInActionSource, - LogInStartingPayload, - LogInResult, +import { + type LogInActionSourceType, + type LogInStartingPayload, + type LogInResult, + loginActionSources, } from '../types/account-types'; import type { Endpoint, SocketAPIHandler } from '../types/endpoints'; import type { LoadingOptions, LoadingInfo } from '../types/loading-types'; @@ -156,7 +156,7 @@ sessionChange: ClientSessionChange, preRequestUserState: ?PreRequestUserState, error: ?string, - source: ?LogInActionSource, + source: ?LogInActionSourceType, ) { dispatch({ type: setNewSessionActionType, @@ -173,7 +173,7 @@ dispatch: Dispatch, cookie: ?string, urlPrefix: string, - source: LogInActionSource, + source: LogInActionSourceType, ): Promise { const resolveInvalidatedCookie = getConfig().resolveInvalidatedCookie; if (!resolveInvalidatedCookie) { @@ -288,7 +288,7 @@ dispatch, newAnonymousCookie, urlPrefix, - cookieInvalidationResolutionAttempt, + loginActionSources.cookieInvalidationResolutionAttempt, ); currentlyWaitingForNewCookie = false; diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -2,7 +2,7 @@ import invariant from 'invariant'; -import type { LogInActionSource } from '../types/account-types'; +import type { LogInActionSourceType } from '../types/account-types'; import type { PlatformDetails } from '../types/device-types'; import type { DispatchRecoveryAttempt } from './action-utils'; import type { FetchJSON } from './fetch-json'; @@ -11,7 +11,7 @@ +resolveInvalidatedCookie: ?( fetchJSON: FetchJSON, dispatchRecoveryAttempt: DispatchRecoveryAttempt, - source?: LogInActionSource, + source?: LogInActionSourceType, ) => Promise, +setCookieOnRequest: boolean, +setSessionIDOnRequest: boolean, 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 @@ -18,11 +18,8 @@ import Icon from 'react-native-vector-icons/FontAwesome'; import { useDispatch } from 'react-redux'; -import { - appStartCookieLoggedInButInvalidRedux, - appStartReduxLoggedInButInvalidCookie, -} from 'lib/actions/user-actions'; import { isLoggedIn } from 'lib/selectors/user-selectors'; +import { loginActionSources } from 'lib/types/account-types'; import type { Dispatch } from 'lib/types/redux-types'; import { fetchNewCookieFromNativeCredentials } from 'lib/utils/action-utils'; @@ -289,8 +286,8 @@ } if (!__DEV__) { const actionSource = loggedIn - ? appStartReduxLoggedInButInvalidCookie - : appStartCookieLoggedInButInvalidRedux; + ? loginActionSources.appStartReduxLoggedInButInvalidCookie + : loginActionSources.appStartCookieLoggedInButInvalidRedux; const sessionChange = await fetchNewCookieFromNativeCredentials( dispatch, cookie, diff --git a/native/account/resolve-invalidated-cookie.js b/native/account/resolve-invalidated-cookie.js --- a/native/account/resolve-invalidated-cookie.js +++ b/native/account/resolve-invalidated-cookie.js @@ -1,7 +1,7 @@ // @flow import { logInActionTypes, logIn } from 'lib/actions/user-actions'; -import type { LogInActionSource } from 'lib/types/account-types'; +import type { LogInActionSourceType } from 'lib/types/account-types'; import type { DispatchRecoveryAttempt } from 'lib/utils/action-utils'; import type { FetchJSON } from 'lib/utils/fetch-json'; @@ -13,7 +13,7 @@ async function resolveInvalidatedCookie( fetchJSON: FetchJSON, dispatchRecoveryAttempt: DispatchRecoveryAttempt, - source?: LogInActionSource, + source?: LogInActionSourceType, ) { const keychainCredentials = await fetchNativeKeychainCredentials(); if (!keychainCredentials) { 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 @@ -5,7 +5,7 @@ import { setMessageStoreMessages } from 'lib/actions/message-actions.js'; import { setThreadStoreActionType } from 'lib/actions/thread-actions'; -import { sqliteLoadFailure } from 'lib/actions/user-actions'; +import { loginActionSources } from 'lib/types/account-types'; import { fetchNewCookieFromNativeCredentials } from 'lib/utils/action-utils'; import { convertClientDBThreadInfosToRawThreadInfos } from 'lib/utils/thread-ops-utils'; @@ -51,7 +51,7 @@ dispatch, cookie, urlPrefix, - sqliteLoadFailure, + loginActionSources.sqliteLoadFailure, ); } finally { setStoreLoaded(true); 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,7 +12,6 @@ logOutActionTypes, deleteAccountActionTypes, logInActionTypes, - sqliteOpFailure, } from 'lib/actions/user-actions'; import baseReducer from 'lib/reducers/master-reducer'; import { processThreadStoreOperations } from 'lib/reducers/thread-reducer'; @@ -20,6 +19,7 @@ invalidSessionDowngrade, invalidSessionRecovery, } from 'lib/shared/account-utils'; +import { loginActionSources } from 'lib/types/account-types'; import { defaultEnabledApps } from 'lib/types/enabled-apps'; import { defaultCalendarFilters } from 'lib/types/filter-types'; import type { Dispatch, BaseAction } from 'lib/types/redux-types'; @@ -347,7 +347,7 @@ cookie: state.cookie, }, error: null, - source: sqliteOpFailure, + source: loginActionSources.sqliteOpFailure, }, }); await persistor.flush();