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,7 @@ // @flow -import { - cookieInvalidationResolutionAttempt, - socketAuthErrorResolutionAttempt, -} from '../actions/user-actions'; -import type { LogInActionSource } from '../types/account-types'; +import type { LogInActionSourceTypes } from '../types/account-types'; +import { loginActionSourceTypes } 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 +57,11 @@ function invalidSessionRecovery( currentReduxState: AppState, actionCurrentUserInfo: CurrentUserInfo, - source: ?LogInActionSource, + source: ?LogInActionSourceTypes, ): boolean { if ( - source !== cookieInvalidationResolutionAttempt && - source !== socketAuthErrorResolutionAttempt + source !== loginActionSourceTypes.cookieInvalidationResolutionAttempt && + source !== loginActionSourceTypes.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, @@ -17,6 +14,7 @@ clientRequestSocketTimeout, } from '../shared/timeouts'; import type { LogOutResult } from '../types/account-types'; +import { loginActionSourceTypes } from '../types/account-types'; import type { CalendarQuery } from '../types/entry-types'; import type { Dispatch } from '../types/redux-types'; import { @@ -454,7 +452,7 @@ this.props.dispatch, cookie, this.props.urlPrefix, - socketAuthErrorResolutionAttempt, + loginActionSourceTypes.socketAuthErrorResolutionAttempt, ); if (!recoverySessionChange && sessionChange) { @@ -471,7 +469,7 @@ }, preRequestUserState: this.initializedWithUserState, error: null, - source: socketAuthErrorResolutionAttempt, + source: loginActionSourceTypes.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 loginActionSourceTypes = 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 LogInActionSourceTypes = $Values; export type LogInStartingPayload = { +calendarQuery: CalendarQuery, - +source?: LogInActionSource, + +source?: LogInActionSourceTypes, }; export type LogInExtraInfo = { @@ -96,7 +101,7 @@ ...LogInExtraInfo, +username: string, +password: string, - +source?: ?LogInActionSource, + +source?: ?LogInActionSourceTypes, }; export type LogInRequest = { @@ -129,7 +134,7 @@ +userInfos: $ReadOnlyArray, +calendarResult: CalendarResult, +updatesCurrentAsOf: number, - +source?: ?LogInActionSource, + +source?: ?LogInActionSourceTypes, }; 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 { LogInActionSourceTypes } 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: ?LogInActionSourceTypes, }; 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,13 +5,13 @@ 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, + LogInActionSourceTypes, LogInStartingPayload, LogInResult, } from '../types/account-types'; +import { loginActionSourceTypes } from '../types/account-types'; import type { Endpoint, SocketAPIHandler } from '../types/endpoints'; import type { LoadingOptions, LoadingInfo } from '../types/loading-types'; import type { @@ -156,7 +156,7 @@ sessionChange: ClientSessionChange, preRequestUserState: ?PreRequestUserState, error: ?string, - source: ?LogInActionSource, + source: ?LogInActionSourceTypes, ) { dispatch({ type: setNewSessionActionType, @@ -173,7 +173,7 @@ dispatch: Dispatch, cookie: ?string, urlPrefix: string, - source: LogInActionSource, + source: LogInActionSourceTypes, ): Promise { const resolveInvalidatedCookie = getConfig().resolveInvalidatedCookie; if (!resolveInvalidatedCookie) { @@ -288,7 +288,7 @@ dispatch, newAnonymousCookie, urlPrefix, - cookieInvalidationResolutionAttempt, + loginActionSourceTypes.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 { LogInActionSourceTypes } 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?: LogInActionSourceTypes, ) => 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 { loginActionSourceTypes } 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; + ? loginActionSourceTypes.appStartReduxLoggedInButInvalidCookie + : loginActionSourceTypes.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 { LogInActionSourceTypes } 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?: LogInActionSourceTypes, ) { 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 { loginActionSourceTypes } 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, + loginActionSourceTypes.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 { loginActionSourceTypes } 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: loginActionSourceTypes.sqliteOpFailure, }, }); await persistor.flush();