diff --git a/lib/components/keyserver-connection-handler.js b/lib/components/keyserver-connection-handler.js --- a/lib/components/keyserver-connection-handler.js +++ b/lib/components/keyserver-connection-handler.js @@ -34,6 +34,7 @@ import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; +import { getMessageForException } from '../utils/errors.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; import { @@ -147,24 +148,26 @@ throw new Error(CANCELLED_ERROR); } - await dispatchActionPromise( - keyserverAuthActionTypes, - keyserverAuthRawAction(innerCallKeyserverEndpoint)({ - userID, - deviceID, - doNotRegister, - calendarQuery, - deviceTokenUpdateInput, - authActionSource, - keyserverData: { - [keyserverID]: { - initialContentEncryptedMessage: contentSession, - initialNotificationsEncryptedMessage: notifsSession, - }, + const authPromise = keyserverAuthRawAction( + innerCallKeyserverEndpoint, + )({ + userID, + deviceID, + doNotRegister, + calendarQuery, + deviceTokenUpdateInput, + authActionSource, + keyserverData: { + [keyserverID]: { + initialContentEncryptedMessage: contentSession, + initialNotificationsEncryptedMessage: notifsSession, }, - preRequestUserInfo, - }), - ); + }, + preRequestUserInfo, + }); + + void dispatchActionPromise(keyserverAuthActionTypes, authPromise); + await authPromise; } catch (e) { if (hasBeenCancelled()) { return; @@ -253,12 +256,30 @@ const innerPerformRecovery = React.useCallback( ( recoveryActionSource: RecoveryActionSource, + setInProgress: boolean => mixed, hasBeenCancelled: () => boolean, ) => async ( callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, innerCallKeyserverEndpoint: CallKeyserverEndpoint, ) => { + if (usingCommServicesAccessToken) { + try { + await innerPerformAuth( + recoveryActionSource, + setInProgress, + hasBeenCancelled, + true, + )(innerCallKeyserverEndpoint); + } catch (e) { + console.log( + `Tried to recover session with keyserver ${keyserverID} but got ` + + `error. Exception: ` + + (getMessageForException(e) ?? '{no exception message}'), + ); + } + return; + } if (!resolveKeyserverSessionInvalidationUsingNativeCredentials) { return; } @@ -273,6 +294,7 @@ ); }, [ + innerPerformAuth, resolveKeyserverSessionInvalidationUsingNativeCredentials, dispatchActionPromise, keyserverID, @@ -296,7 +318,11 @@ try { await keyserverRecoveryLogIn( recoveryActionSource, - innerPerformRecovery(recoveryActionSource, hasBeenCancelled), + innerPerformRecovery( + recoveryActionSource, + setAuthInProgress, + hasBeenCancelled, + ), hasBeenCancelled, ); } finally {