diff --git a/web/src/App.tsx b/web/src/App.tsx index 94796648b..07bdcaf22 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -17,10 +17,10 @@ import NotificationsContext from './hooks/NotificationsContext'; import { Notification } from './models/Notifications'; import NotificationBar from './components/NotificationBar'; import SignOut from './views/LoginPortal/SignOut/SignOut'; -import { useRememberMe, useResetPassword } from './hooks/Configuration'; +import { getRememberMe, getResetPassword } from './utils/Configuration'; import '@fortawesome/fontawesome-svg-core/styles.css' import { config as faConfig } from '@fortawesome/fontawesome-svg-core'; -import { useBasePath } from './hooks/BasePath'; +import { getBasePath } from './utils/BasePath'; faConfig.autoAddCss = false; @@ -29,7 +29,7 @@ const App: React.FC = () => { return ( - + setNotification(null)} /> @@ -49,8 +49,8 @@ const App: React.FC = () => { + rememberMe={getRememberMe()} + resetPassword={getResetPassword()} /> diff --git a/web/src/hooks/AssetPath.ts b/web/src/hooks/AssetPath.ts deleted file mode 100644 index 2ac45d9e7..000000000 --- a/web/src/hooks/AssetPath.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { useBasePath } from "./BasePath"; - -__webpack_public_path__ = "/" - -if (useBasePath() !== "") { - __webpack_public_path__ = useBasePath() + "/" -} \ No newline at end of file diff --git a/web/src/hooks/BasePath.ts b/web/src/hooks/BasePath.ts deleted file mode 100644 index 938bea2cf..000000000 --- a/web/src/hooks/BasePath.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { useEmbeddedVariable } from "./Configuration"; - -export function useBasePath() { - return useEmbeddedVariable("basepath"); -} \ No newline at end of file diff --git a/web/src/hooks/Configuration.ts b/web/src/hooks/Configuration.ts index 0d445cbf3..921532b3b 100644 --- a/web/src/hooks/Configuration.ts +++ b/web/src/hooks/Configuration.ts @@ -1,23 +1,6 @@ import { useRemoteCall } from "./RemoteCall"; import { getConfiguration } from "../services/Configuration"; -export function useEmbeddedVariable(variableName: string) { - const value = document.body.getAttribute(`data-${variableName}`); - if (value === null) { - throw new Error(`No ${variableName} embedded variable detected`); - } - - return value; -} - -export function useRememberMe() { - return useEmbeddedVariable("rememberme") === "true"; -} - -export function useResetPassword() { - return useEmbeddedVariable("disable-resetpassword") === "true"; -} - export function useConfiguration() { return useRemoteCall(getConfiguration, []); } \ No newline at end of file diff --git a/web/src/index.tsx b/web/src/index.tsx index f4f0819bf..cff565f93 100644 --- a/web/src/index.tsx +++ b/web/src/index.tsx @@ -1,4 +1,4 @@ -import './hooks/AssetPath'; +import './utils/AssetPath'; import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; diff --git a/web/src/services/Api.ts b/web/src/services/Api.ts index 2f81dd343..07446b163 100644 --- a/web/src/services/Api.ts +++ b/web/src/services/Api.ts @@ -1,7 +1,7 @@ import { AxiosResponse } from "axios"; -import { useBasePath } from "../hooks/BasePath"; +import { getBasePath } from "../utils/BasePath"; -const basePath = useBasePath(); +const basePath = getBasePath(); export const FirstFactorPath = basePath + "/api/firstfactor"; export const InitiateTOTPRegistrationPath = basePath + "/api/secondfactor/totp/identity/start"; diff --git a/web/src/utils/AssetPath.ts b/web/src/utils/AssetPath.ts new file mode 100644 index 000000000..358130b89 --- /dev/null +++ b/web/src/utils/AssetPath.ts @@ -0,0 +1,7 @@ +import { getBasePath } from "./BasePath"; + +__webpack_public_path__ = "/" + +if (getBasePath() !== "") { + __webpack_public_path__ = getBasePath() + "/" +} \ No newline at end of file diff --git a/web/src/utils/BasePath.ts b/web/src/utils/BasePath.ts new file mode 100644 index 000000000..5c5553c94 --- /dev/null +++ b/web/src/utils/BasePath.ts @@ -0,0 +1,5 @@ +import { getEmbeddedVariable } from "./Configuration"; + +export function getBasePath() { + return getEmbeddedVariable("basepath"); +} \ No newline at end of file diff --git a/web/src/utils/Configuration.ts b/web/src/utils/Configuration.ts new file mode 100644 index 000000000..61249a9a2 --- /dev/null +++ b/web/src/utils/Configuration.ts @@ -0,0 +1,16 @@ +export function getEmbeddedVariable(variableName: string) { + const value = document.body.getAttribute(`data-${variableName}`); + if (value === null) { + throw new Error(`No ${variableName} embedded variable detected`); + } + + return value; +} + +export function getRememberMe() { + return getEmbeddedVariable("rememberme") === "true"; +} + +export function getResetPassword() { + return getEmbeddedVariable("disable-resetpassword") === "true"; +} \ No newline at end of file