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 @@ -16,6 +16,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'; @@ -79,10 +80,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 { @@ -134,6 +143,8 @@ `Error while authenticating to keyserver with id ${keyserverID}`, e, ); + } finally { + authInProgress.current = false; } })(); }, [ @@ -146,6 +157,7 @@ keyserverAuth, deviceToken, calendarQuery, + isUserAuthenticated, ]); if (keyserverID !== ashoatKeyserverID) {