diff --git a/src/synapse/authProvider.js b/src/synapse/authProvider.js index 5068c44..30ce600 100644 --- a/src/synapse/authProvider.js +++ b/src/synapse/authProvider.js @@ -1,12 +1,5 @@ import { fetchUtils } from "react-admin"; -const stripTrailingSlash = str => { - if (!str) { - return; - } - return str.endsWith("/") ? str.slice(0, -1) : str; -}; - const authProvider = { // called when the user attempts to log in login: ({ base_url, username, password }) => { @@ -20,15 +13,16 @@ const authProvider = { }), }; + // use the base_url from login instead of the well_known entry from the + // server, since the admin might want to access the admin API via some + // private address + localStorage.setItem("base_url", base_url); + const decoded_base_url = window.decodeURIComponent(base_url); const login_api_url = decoded_base_url + "/_matrix/client/r0/login"; return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => { - const normalized_base_url = stripTrailingSlash( - json.well_known["m.homeserver"].base_url - ); - localStorage.setItem("base_url", normalized_base_url); - localStorage.setItem("home_server_url", json.home_server); + localStorage.setItem("home_server", json.home_server); localStorage.setItem("user_id", json.user_id); localStorage.setItem("access_token", json.access_token); localStorage.setItem("device_id", json.device_id);