diff --git a/src/components/LoginPage.jsx b/src/components/LoginPage.jsx index 3209003..a5f3d95 100644 --- a/src/components/LoginPage.jsx +++ b/src/components/LoginPage.jsx @@ -7,6 +7,7 @@ import { useLogin, useNotify, useLocaleState, + useStoreContext, useTranslate, PasswordInput, TextInput, @@ -84,11 +85,12 @@ const FormBox = styled(Box)(({ theme }) => ({ const LoginPage = ({ cfg_base_url }) => { const login = useLogin(); const notify = useNotify(); + const store = useStoreContext(); const [loading, setLoading] = useState(false); const [supportPassAuth, setSupportPassAuth] = useState(true); const [locale, setLocale] = useLocaleState(); const translate = useTranslate(); - const base_url = localStorage.getItem("base_url"); + const base_url = store.getItem("base_url"); const [ssoBaseUrl, setSSOBaseUrl] = useState(""); const loginToken = /\?loginToken=([a-zA-Z0-9_-]+)/.exec(window.location.href); @@ -101,8 +103,8 @@ const LoginPage = ({ cfg_base_url }) => { "", window.location.href.replace(loginToken[0], "#").split("#")[0] ); - const baseUrl = localStorage.getItem("sso_base_url"); - localStorage.removeItem("sso_base_url"); + const baseUrl = store.getItem("sso_base_url"); + store.removeItem("sso_base_url"); if (baseUrl) { const auth = { base_url: baseUrl, @@ -168,7 +170,7 @@ const LoginPage = ({ cfg_base_url }) => { }; const handleSSO = () => { - localStorage.setItem("sso_base_url", ssoBaseUrl); + store.setItem("sso_base_url", ssoBaseUrl); const ssoFullUrl = `${ssoBaseUrl}/_matrix/client/r0/login/sso/redirect?redirectUrl=${encodeURIComponent( window.location.href )}`; diff --git a/src/synapse/authProvider.js b/src/synapse/authProvider.js index 38e5071..62ee1e5 100644 --- a/src/synapse/authProvider.js +++ b/src/synapse/authProvider.js @@ -1,6 +1,6 @@ import { fetchUtils } from "react-admin"; -const authProvider = fixed_base_url => ({ +const authProvider = (fixed_base_url, store) => ({ // called when the user attempts to log in login: ({ base_url, username, password, loginToken }) => { // force homeserver for protection in case the form is manipulated @@ -12,7 +12,7 @@ const authProvider = fixed_base_url => ({ body: JSON.stringify( Object.assign( { - device_id: localStorage.getItem("device_id"), + device_id: store.getItem("device_id"), initial_device_display_name: "Synapse Admin", }, loginToken @@ -33,16 +33,16 @@ const authProvider = fixed_base_url => ({ // server, since the admin might want to access the admin API via some // private address base_url = base_url.replace(/\/+$/g, ""); - localStorage.setItem("base_url", base_url); + store.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 }) => { - 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); + store.setItem("home_server", json.home_server); + store.setItem("user_id", json.user_id); + store.setItem("access_token", json.access_token); + store.setItem("device_id", json.device_id); }); }, // called when the user clicks on the logout button