mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-12-23 13:33:18 +00:00
Save base_url from login input
Change-Id: I58447145dfc2df4ab3544b6a165721f900e29b24
This commit is contained in:
parent
1fb89c9e58
commit
2d0ce50444
1 changed files with 6 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue