diff --git a/packages/api/src/controllers/config.js b/packages/api/src/controllers/config.js index 699f48a8..25b253bc 100644 --- a/packages/api/src/controllers/config.js +++ b/packages/api/src/controllers/config.js @@ -17,6 +17,7 @@ const { checkLicense, checkLicenseKey } = require('../utility/checkLicense'); const storage = require('./storage'); const { getAuthProxyUrl } = require('../utility/authProxy'); const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint'); +const { extractErrorMessage } = require('dbgate-tools'); const lock = new AsyncLock(); @@ -39,10 +40,12 @@ module.exports = { const isUserLoggedIn = authProvider.isUserLoggedIn(req); const singleConid = authProvider.getSingleConnectionId(req); + const storageConnectionError = storage.getStorageConnectionError(); - const singleConnection = singleConid - ? await connections.getCore({ conid: singleConid }) - : connections.singleConnection; + const singleConnection = + singleConid && !storageConnectionError + ? await connections.getCore({ conid: singleConid }) + : connections.singleConnection; let configurationError = null; if (process.env.STORAGE_DATABASE && process.env.BASIC_AUTH) { @@ -50,8 +53,13 @@ module.exports = { 'Basic authentization is not allowed, when using storage. Cannot use both STORAGE_DATABASE and BASIC_AUTH'; } - const checkedLicense = await checkLicense(); + if (storageConnectionError && !configurationError) { + configurationError = extractErrorMessage(storageConnectionError); + } + + const checkedLicense = storageConnectionError ? null : await checkLicense(); const isLicenseValid = checkedLicense?.status == 'ok'; + const logoutUrl = storageConnectionError ? null : await authProvider.getLogoutUrl(); return { runAsPortal: !!connections.portalConnections, @@ -68,7 +76,7 @@ module.exports = { trialDaysLeft: checkedLicense?.isGeneratedTrial && !checkedLicense?.isExpired ? checkedLicense?.daysLeft : null, checkedLicense, configurationError, - logoutUrl: await authProvider.getLogoutUrl(), + logoutUrl, permissions, login, // ...additionalConfigProps, diff --git a/packages/api/src/controllers/storage.js b/packages/api/src/controllers/storage.js index 871b7ad2..3f9dd9dc 100644 --- a/packages/api/src/controllers/storage.js +++ b/packages/api/src/controllers/storage.js @@ -17,4 +17,8 @@ module.exports = { async getConnectionsForLoginPage() { return null; }, + + getStorageConnectionError() { + return null; + } }; diff --git a/packages/web/src/LoginPage.svelte b/packages/web/src/LoginPage.svelte index 6bd89cba..b1b0af48 100644 --- a/packages/web/src/LoginPage.svelte +++ b/packages/web/src/LoginPage.svelte @@ -125,6 +125,13 @@ } internalRedirectTo(`/not-logged.html`); } + + $: { + if ($config?.configurationError) { + console.log('Configuration error', $config); + internalRedirectTo(`/error.html`); + } + }