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,25 @@ throw new Error(CANCELLED_ERROR); } - await dispatchActionPromise( - keyserverAuthActionTypes, - keyserverAuthRawAction(innerCallKeyserverEndpoint)({ - userID, - deviceID, - doNotRegister, - calendarQuery, - deviceTokenUpdateInput, - authActionSource, - keyserverData: { - [keyserverID]: { - initialContentEncryptedMessage: contentSession.message, - initialNotificationsEncryptedMessage: notifsSession, - }, + const authPromise = keyserverAuthRawAction( + innerCallKeyserverEndpoint, + )({ + userID, + deviceID, + doNotRegister, + calendarQuery, + deviceTokenUpdateInput, + authActionSource, + keyserverData: { + [keyserverID]: { + initialContentEncryptedMessage: contentSession.message, + initialNotificationsEncryptedMessage: notifsSession, }, - preRequestUserInfo, - }), - ); + }, + preRequestUserInfo, + }); + + await dispatchActionPromise(keyserverAuthActionTypes, authPromise); } catch (e) { if (hasBeenCancelled()) { return; @@ -253,12 +255,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 +293,7 @@ ); }, [ + innerPerformAuth, resolveKeyserverSessionInvalidationUsingNativeCredentials, dispatchActionPromise, keyserverID, @@ -296,7 +317,11 @@ try { await keyserverRecoveryLogIn( recoveryActionSource, - innerPerformRecovery(recoveryActionSource, hasBeenCancelled), + innerPerformRecovery( + recoveryActionSource, + setAuthInProgress, + hasBeenCancelled, + ), hasBeenCancelled, ); } finally {