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 @@ -24,6 +24,7 @@ import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; import { usingCommServicesAccessToken } from '../utils/services-utils.js'; +import sleep from '../utils/sleep.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; type Props = { @@ -31,6 +32,9 @@ +keyserverID: string, +socketComponent: React.ComponentType, }; + +const AUTH_RETRY_DELAY_MS = 60_000; + function KeyserverConnectionHandler(props: Props) { const { socketComponent: Socket, keyserverID, ...rest } = props; @@ -81,18 +85,18 @@ const olmSessionCreator = React.useContext(OlmSessionCreatorContext); invariant(olmSessionCreator, 'Olm session creator should be set'); - const authInProgress = React.useRef(false); + const [canPerformAuth, setCanPerformAuth] = React.useState(true); const isUserAuthenticated = useSelector(isLoggedInToKeyserver(keyserverID)); React.useEffect(() => { if ( !usingCommServicesAccessToken || - authInProgress.current || + !canPerformAuth || isUserAuthenticated ) { return; } - authInProgress.current = true; + setCanPerformAuth(false); void (async () => { try { @@ -148,7 +152,8 @@ await dispatchActionPromise(logOutActionTypes, callLogOut()); } } finally { - authInProgress.current = false; + await sleep(AUTH_RETRY_DELAY_MS); + setCanPerformAuth(true); } })(); }, [ @@ -164,6 +169,7 @@ isUserAuthenticated, callLogOut, dataLoaded, + canPerformAuth, ]); if (keyserverID !== ashoatKeyserverID) {