diff --git a/CHANGELOG.md b/CHANGELOG.md index 774748c2..0e519f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- [#228](https://github.com/os2display/display-admin-client/pull/228) + - Changed login page to only get oidc urls when a login button has been clicked. - [#227](https://github.com/os2display/display-admin-client/pull/227) - Changed how theme is loaded following change to API - Added fetch all to avoid removing slides when saving playlist and all slides have not been fetched. diff --git a/src/components/user/login.jsx b/src/components/user/login.jsx index 27cec696..3a8f9ab5 100644 --- a/src/components/user/login.jsx +++ b/src/components/user/login.jsx @@ -208,7 +208,7 @@ function Login() { }, { type: "oidc", - provider: "internal", + provider: "external", enabled: true, label: null, icon: null, diff --git a/src/components/user/oidc-login.jsx b/src/components/user/oidc-login.jsx index e00bbf55..2c91aead 100644 --- a/src/components/user/oidc-login.jsx +++ b/src/components/user/oidc-login.jsx @@ -25,30 +25,6 @@ function OIDCLogin({ config }) { const [oidcAuthUrl, setOidcAuthUrl] = useState(""); const [oidcAuthLoadingError, setOidcAuthLoadingError] = useState(""); - useEffect(() => { - if (!provider) { - return; - } - - ConfigLoader.loadConfig().then((siteConfig) => { - fetch( - `${siteConfig.api}v1/authentication/oidc/urls?providerKey=${provider}`, - { - mode: "cors", - credentials: "include", - } - ) - .then((resp) => { - resp.json().then((data) => { - setOidcAuthUrl(data.authorizationUrl); - }); - }) - .catch(() => { - setOidcAuthLoadingError(t("error-fetching-oidc-urls")); - }); - }); - }, [provider]); - let labelText = label; if (labelText === null) { @@ -76,23 +52,38 @@ function OIDCLogin({ config }) { } } + const onClick = () => { + ConfigLoader.loadConfig().then((siteConfig) => { + fetch( + `${siteConfig.api}v1/authentication/oidc/urls?providerKey=${provider}`, + { + mode: "cors", + credentials: "include", + } + ) + .then((resp) => { + resp.json().then((data) => { + window.location.href = data.authorizationUrl; + }); + }) + .catch(() => { + setOidcAuthLoadingError(t("error-fetching-oidc-urls")); + }); + }); + }; + return ( <> - {!oidcAuthUrl && ( - - )} - {oidcAuthUrl !== "" && ( - - {iconRender} - {labelText} - - )} +
+ {iconRender} + {labelText} +
{oidcAuthLoadingError !== "" && ( {oidcAuthLoadingError} )}