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 @@ -15,6 +15,7 @@ cookieSelector, deviceTokenSelector, } from '../selectors/keyserver-selectors.js'; +import { isLoggedInToKeyserver } from '../selectors/user-selectors.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import { OlmSessionCreatorContext } from '../shared/olm-session-creator-context.js'; import type { BaseSocketProps } from '../socket/socket.react.js'; @@ -75,10 +76,18 @@ const olmSessionCreator = React.useContext(OlmSessionCreatorContext); invariant(olmSessionCreator, 'Olm session creator should be set'); + const authInProgress = React.useRef(false); + const isUserAuthenticated = useSelector(isLoggedInToKeyserver(keyserverID)); + React.useEffect(() => { - if (!usingCommServicesAccessToken) { + if ( + !usingCommServicesAccessToken || + authInProgress.current || + isUserAuthenticated + ) { return; } + authInProgress.current = true; void (async () => { try { @@ -130,6 +139,8 @@ `Error while authenticating to keyserver with id ${keyserverID}`, e, ); + } finally { + authInProgress.current = false; } })(); }, [ @@ -142,6 +153,7 @@ keyserverAuth, deviceToken, calendarQuery, + isUserAuthenticated, ]); if (keyserverID !== ashoatKeyserverID) {