Save base_url from login input

Change-Id: I58447145dfc2df4ab3544b6a165721f900e29b24
This commit is contained in:
Manuel Stahl 2020-05-02 15:35:15 +02:00
parent 1fb89c9e58
commit 2d0ce50444

View file

@ -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);