From 230925e159466f3253b10d018ce28302c891584e Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Thu, 10 Oct 2024 23:36:32 +0300 Subject: [PATCH] Only connect to ServerConnections once (#6150) * Only connect to ServerConnections once * Fix initial login after wizard completion * Fix login when refreshing login or select server page --- src/components/ConnectionRequired.tsx | 27 +++++++++++++++------------ src/components/ServerConnections.js | 1 + src/index.jsx | 3 +++ 3 files changed, 19 insertions(+), 12 deletions(-) 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();