diff --git a/src/components/ConnectionRequired.tsx b/src/components/ConnectionRequired.tsx index 960ead7d76..41b96cb360 100644 --- a/src/components/ConnectionRequired.tsx +++ b/src/components/ConnectionRequired.tsx @@ -149,19 +149,22 @@ const ConnectionRequired: FunctionComponent = ({ useEffect(() => { // Check connection status on initial page load - ServerConnections.connect() - .then(firstConnection => { - console.debug('[ConnectionRequired] connection state', firstConnection?.State); + const apiClient = ServerConnections.currentApiClient(); + const firstConnection = ServerConnections.firstConnection; + console.debug('[ConnectionRequired] connection state', firstConnection?.State); + ServerConnections.firstConnection = null; - if (firstConnection && firstConnection.State !== ConnectionState.SignedIn) { - return handleIncompleteWizard(firstConnection); - } else { - return validateUserAccess(); - } - }) - .catch(err => { - console.error('[ConnectionRequired] failed to connect to server', err); - }); + if (firstConnection && firstConnection.State !== ConnectionState.SignedIn && !apiClient?.isLoggedIn()) { + handleIncompleteWizard(firstConnection) + .catch(err => { + console.error('[ConnectionRequired] could not start wizard', err); + }); + } else { + validateUserAccess() + .catch(err => { + console.error('[ConnectionRequired] could not validate user access', err); + }); + } }, [handleIncompleteWizard, validateUserAccess]); if (isLoading) { diff --git a/src/components/ServerConnections.js b/src/components/ServerConnections.js index 93aff18584..be2ac43877 100644 --- a/src/components/ServerConnections.js +++ b/src/components/ServerConnections.js @@ -33,6 +33,7 @@ class ServerConnections extends ConnectionManager { constructor() { super(...arguments); this.localApiClient = null; + this.firstConnection = null; // Set the apiclient minimum version to match the SDK this._minServerVersion = MINIMUM_VERSION; diff --git a/src/index.jsx b/src/index.jsx index dac6f72e8b..cbbc633ce6 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -110,6 +110,9 @@ build: ${__JF_BUILD_VERSION__}`); Events.on(apiClient, 'requestfail', appRouter.onRequestFail); }); + // Connect to server + ServerConnections.firstConnection = await ServerConnections.connect(); + // Render the app await renderApp();