Changeset View
Changeset View
Standalone View
Standalone View
native/account/resolve-invalidated-cookie.js
// @flow | // @flow | ||||
import { logInActionTypes, logIn } from 'lib/actions/user-actions.js'; | import { logInActionTypes, logIn } from 'lib/actions/user-actions.js'; | ||||
import type { LogInActionSource } from 'lib/types/account-types.js'; | import type { LogInActionSource } from 'lib/types/account-types.js'; | ||||
import type { DispatchRecoveryAttempt } from 'lib/utils/action-utils.js'; | import type { DispatchRecoveryAttempt } from 'lib/utils/action-utils.js'; | ||||
import type { CallServerEndpoint } from 'lib/utils/call-server-endpoint.js'; | import type { CallServerEndpoint } from 'lib/utils/call-server-endpoint.js'; | ||||
import { fetchNativeKeychainCredentials } from './native-credentials.js'; | import { fetchNativeKeychainCredentials } from './native-credentials.js'; | ||||
import { getGlobalNavContext } from '../navigation/icky-global.js'; | import { getGlobalNavContext } from '../navigation/icky-global.js'; | ||||
import { store } from '../redux/redux-setup.js'; | import { store } from '../redux/redux-setup.js'; | ||||
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | ||||
async function resolveInvalidatedCookie( | async function resolveInvalidatedCookie( | ||||
callServerEndpoint: CallServerEndpoint, | callServerEndpoint: CallServerEndpoint, | ||||
dispatchRecoveryAttempt: DispatchRecoveryAttempt, | dispatchRecoveryAttempt: DispatchRecoveryAttempt, | ||||
logInActionSource: LogInActionSource, | logInActionSource: LogInActionSource, | ||||
getInitialNotificationsEncryptedMessage?: () => Promise<string>, | |||||
) { | ) { | ||||
const keychainCredentials = await fetchNativeKeychainCredentials(); | const keychainCredentials = await fetchNativeKeychainCredentials(); | ||||
if (!keychainCredentials) { | if (!keychainCredentials) { | ||||
return; | return; | ||||
} | } | ||||
const extraInfo = await nativeLogInExtraInfoSelector({ | let extraInfo = await nativeLogInExtraInfoSelector({ | ||||
redux: store.getState(), | redux: store.getState(), | ||||
navContext: getGlobalNavContext(), | navContext: getGlobalNavContext(), | ||||
})(); | })(); | ||||
if (getInitialNotificationsEncryptedMessage) { | |||||
const initialNotificationsEncryptedMessage = | |||||
await getInitialNotificationsEncryptedMessage(); | |||||
extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage }; | |||||
} | |||||
const { calendarQuery } = extraInfo; | const { calendarQuery } = extraInfo; | ||||
await dispatchRecoveryAttempt( | await dispatchRecoveryAttempt( | ||||
logInActionTypes, | logInActionTypes, | ||||
logIn(callServerEndpoint)({ | logIn(callServerEndpoint)({ | ||||
...keychainCredentials, | ...keychainCredentials, | ||||
...extraInfo, | ...extraInfo, | ||||
logInActionSource, | logInActionSource, | ||||
}), | }), | ||||
{ calendarQuery }, | { calendarQuery }, | ||||
); | ); | ||||
} | } | ||||
export { resolveInvalidatedCookie }; | export { resolveInvalidatedCookie }; |