forked from matrix/element-web
Merge pull request #9892 from vector-im/travis/check-login-for-config
Use the user's pre-existing HS when config validation fails
This commit is contained in:
commit
1459bfe7be
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.",
|
"Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.",
|
||||||
|
"This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below": "This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below",
|
||||||
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
|
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
|
||||||
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
|
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
|
||||||
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
|
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
|
||||||
|
|
|
@ -48,6 +48,7 @@ import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler';
|
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils';
|
import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils';
|
||||||
import {AutoDiscovery} from "matrix-js-sdk/lib/autodiscovery";
|
import {AutoDiscovery} from "matrix-js-sdk/lib/autodiscovery";
|
||||||
|
import * as Lifecycle from "matrix-react-sdk/lib/Lifecycle";
|
||||||
|
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
|
||||||
|
@ -365,8 +366,17 @@ async function loadApp() {
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
const errorMessage = err.translatedMessage
|
let errorMessage = err.translatedMessage
|
||||||
|| _t("Unexpected error preparing the app. See console for details.");
|
|| _t("Unexpected error preparing the app. See console for details.");
|
||||||
|
errorMessage = <span>
|
||||||
|
{_t(
|
||||||
|
"This installation of Riot seems to have an invalid server configuration. " +
|
||||||
|
"If you are the administrator, please correct the error below",
|
||||||
|
)}
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
{errorMessage}
|
||||||
|
</span>;
|
||||||
|
|
||||||
// Like the compatibility page, AWOOOOOGA at the user
|
// Like the compatibility page, AWOOOOOGA at the user
|
||||||
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
|
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
|
||||||
|
@ -447,6 +457,8 @@ async function loadLanguage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function verifyServerConfig() {
|
async function verifyServerConfig() {
|
||||||
|
let validatedConfig;
|
||||||
|
try {
|
||||||
console.log("Verifying homeserver configuration");
|
console.log("Verifying homeserver configuration");
|
||||||
|
|
||||||
// Note: the query string may include is_url and hs_url - we only respect these in the
|
// Note: the query string may include is_url and hs_url - we only respect these in the
|
||||||
|
@ -461,12 +473,14 @@ async function verifyServerConfig() {
|
||||||
|
|
||||||
const incompatibleOptions = [wkConfig, serverName, hsUrl].filter(i => !!i);
|
const incompatibleOptions = [wkConfig, serverName, hsUrl].filter(i => !!i);
|
||||||
if (incompatibleOptions.length > 1) {
|
if (incompatibleOptions.length > 1) {
|
||||||
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
throw newTranslatableError(_td(
|
throw newTranslatableError(_td(
|
||||||
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
|
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
|
||||||
"or default_hs_url.",
|
"or default_hs_url.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (incompatibleOptions.length < 1) {
|
if (incompatibleOptions.length < 1) {
|
||||||
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
throw newTranslatableError(_td("Invalid configuration: no default server specified."));
|
throw newTranslatableError(_td("Invalid configuration: no default server specified."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,19 +499,33 @@ async function verifyServerConfig() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = null;
|
let discoveryResult = null;
|
||||||
|
|
||||||
if (wkConfig) {
|
if (wkConfig) {
|
||||||
console.log("Config uses a default_server_config - validating object");
|
console.log("Config uses a default_server_config - validating object");
|
||||||
result = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
|
discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverName) {
|
if (serverName) {
|
||||||
console.log("Config uses a default_server_name - doing .well-known lookup");
|
console.log("Config uses a default_server_name - doing .well-known lookup");
|
||||||
result = await AutoDiscovery.findClientConfig(serverName);
|
discoveryResult = await AutoDiscovery.findClientConfig(serverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, result);
|
validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult);
|
||||||
|
} catch (e) {
|
||||||
|
const {hsUrl, isUrl, userId} = Lifecycle.getLocalStorageSessionVars();
|
||||||
|
if (hsUrl && userId) {
|
||||||
|
console.error(e);
|
||||||
|
console.warn("A session was found - suppressing config error and using the session's homeserver");
|
||||||
|
|
||||||
|
console.log("Using pre-existing hsUrl and isUrl: ", {hsUrl, isUrl});
|
||||||
|
validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl);
|
||||||
|
} else {
|
||||||
|
// the user is not logged in, so scream
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
validatedConfig.isDefault = true;
|
validatedConfig.isDefault = true;
|
||||||
|
|
||||||
// Just in case we ever have to debug this
|
// Just in case we ever have to debug this
|
||||||
|
|
Loading…
Reference in New Issue