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 @@ -124,7 +124,7 @@ invariant(identityContext, 'Identity context should be set'); const { identityClient, getAuthMetadata } = identityContext; - const preRequestUserInfo = useSelector(state => state.currentUserInfo); + const currentUserInfo = useSelector(state => state.currentUserInfo); const innerPerformAuth = React.useCallback( ( authActionSource: AuthActionSource, @@ -185,7 +185,7 @@ initialNotificationsEncryptedMessage: notifsSession, }, }, - preRequestUserInfo, + preRequestUserInfo: currentUserInfo, }); await dispatchActionPromise(keyserverAuthActionTypes, authPromise); @@ -216,7 +216,7 @@ identityClient, keyserverID, olmAPI, - preRequestUserInfo, + currentUserInfo, ], ); @@ -362,14 +362,21 @@ const cancelPendingAuth = React.useRef void>(null); const prevPerformAuth = React.useRef(performAuth); - const isUserAuthenticated = useSelector(isLoggedInToKeyserver(keyserverID)); const hasAccessToken = useSelector(state => !!state.commServicesAccessToken); + const isUserLoggedInToKeyserver = useSelector( + isLoggedInToKeyserver(keyserverID), + ); + const canInitiateRecovery = + !!currentUserInfo && + !currentUserInfo.anonymous && + isUserLoggedInToKeyserver; + const cancelPendingRecovery = React.useRef void>(null); const prevPerformRecovery = React.useRef(performRecovery); React.useEffect(() => { - if (activeSessionRecovery && isUserAuthenticated) { + if (activeSessionRecovery && canInitiateRecovery) { cancelPendingAuth.current?.(); cancelPendingAuth.current = null; @@ -397,7 +404,7 @@ if ( !usingCommServicesAccessToken || - isUserAuthenticated || + isUserLoggedInToKeyserver || !hasAccessToken ) { return; @@ -420,7 +427,8 @@ authInProgress, performRecovery, hasAccessToken, - isUserAuthenticated, + isUserLoggedInToKeyserver, + canInitiateRecovery, performAuth, ]);