From e19c34324bd8479af628e5f567d647c0ab78e8cf Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 18 May 2021 12:39:53 +0200 Subject: [PATCH] Allow fixed homeserver (#142) --- .env | 5 +++++ README.md | 5 +++++ src/components/LoginPage.js | 10 +++++++--- src/synapse/authProvider.js | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..7bc3e94 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +# This setting allows to fix the homeserver. +# If you set this setting, the user will not be able to select +# the server and have to use synapse-admin with this server. + +#REACT_APP_SERVER=https://yourmatrixserver.example.com \ No newline at end of file diff --git a/README.md b/README.md index 93053d5..a0a8af1 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ Steps for 1): - download dependencies: `yarn install` - start web server: `yarn start` +You can fix the homeserver, so that the user can no longer define it himself. +Either you define it at startup (e.g. `REACT_APP_SERVER=https://yourmatrixserver.example.com yarn start`) +or by editing it in the [.env](.env) file. See also the +[documentation](https://create-react-app.dev/docs/adding-custom-environment-variables/). + Steps for 2): - run the Docker container from the public docker registry: `docker run -p 8080:80 awesometechnologies/synapse-admin` or use the (docker-compose.yml)[docker-compose.yml]: `docker-compose up -d` diff --git a/src/components/LoginPage.js b/src/components/LoginPage.js index e432904..6c439a5 100644 --- a/src/components/LoginPage.js +++ b/src/components/LoginPage.js @@ -82,6 +82,7 @@ const LoginPage = ({ theme }) => { const setLocale = useSetLocale(); const translate = useTranslate(); const base_url = localStorage.getItem("base_url"); + const cfg_base_url = process.env.REACT_APP_SERVER; const renderInput = ({ meta: { touched, error } = {}, @@ -149,7 +150,7 @@ const LoginPage = ({ theme }) => { const [serverVersion, setServerVersion] = useState(""); const handleUsernameChange = _ => { - if (formData.base_url) return; + if (formData.base_url || cfg_base_url) return; // check if username is a full qualified userId then set base_url accordially const home_server = extractHomeServer(formData.username); const wellKnownUrl = `https://${home_server}/.well-known/matrix/client`; @@ -201,6 +202,7 @@ const LoginPage = ({ theme }) => { label={translate("ra.auth.username")} disabled={loading} onBlur={handleUsernameChange} + resettable fullWidth /> @@ -211,6 +213,7 @@ const LoginPage = ({ theme }) => { label={translate("ra.auth.password")} type="password" disabled={loading} + resettable fullWidth /> @@ -219,7 +222,8 @@ const LoginPage = ({ theme }) => { name="base_url" component={renderInput} label={translate("synapseadmin.auth.base_url")} - disabled={loading} + disabled={cfg_base_url || loading} + resettable fullWidth /> @@ -230,7 +234,7 @@ const LoginPage = ({ theme }) => { return (