2022-04-04 09:15:26 +07:00
|
|
|
import React, { useState, useEffect, Suspense } from "react";
|
2021-01-02 17:58:24 +07:00
|
|
|
|
2022-06-21 07:35:30 +07:00
|
|
|
import createCache from "@emotion/cache";
|
|
|
|
import { CacheProvider } from "@emotion/react";
|
2021-01-02 17:58:24 +07:00
|
|
|
import { config as faConfig } from "@fortawesome/fontawesome-svg-core";
|
2022-06-21 07:35:30 +07:00
|
|
|
import { CssBaseline, ThemeProvider } from "@mui/material";
|
2021-11-05 09:36:52 +07:00
|
|
|
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
|
2021-01-02 17:58:24 +07:00
|
|
|
|
2021-06-19 15:20:43 +07:00
|
|
|
import NotificationBar from "@components/NotificationBar";
|
2019-11-19 06:37:36 +07:00
|
|
|
import {
|
2022-03-03 18:20:43 +07:00
|
|
|
ConsentRoute,
|
|
|
|
IndexRoute,
|
|
|
|
LogoutRoute,
|
|
|
|
RegisterOneTimePasswordRoute,
|
|
|
|
RegisterWebauthnRoute,
|
2021-01-02 17:58:24 +07:00
|
|
|
ResetPasswordStep2Route,
|
|
|
|
ResetPasswordStep1Route,
|
2021-06-19 15:20:43 +07:00
|
|
|
} from "@constants/Routes";
|
|
|
|
import NotificationsContext from "@hooks/NotificationsContext";
|
|
|
|
import { Notification } from "@models/Notifications";
|
|
|
|
import * as themes from "@themes/index";
|
|
|
|
import { getBasePath } from "@utils/BasePath";
|
2022-04-04 14:46:55 +07:00
|
|
|
import {
|
|
|
|
getDuoSelfEnrollment,
|
|
|
|
getRememberMe,
|
|
|
|
getResetPassword,
|
|
|
|
getResetPasswordCustomURL,
|
|
|
|
getTheme,
|
|
|
|
} from "@utils/Configuration";
|
2021-06-19 15:20:43 +07:00
|
|
|
import RegisterOneTimePassword from "@views/DeviceRegistration/RegisterOneTimePassword";
|
2022-03-03 18:20:43 +07:00
|
|
|
import RegisterWebauthn from "@views/DeviceRegistration/RegisterWebauthn";
|
2022-04-04 09:15:26 +07:00
|
|
|
import BaseLoadingPage from "@views/LoadingPage/BaseLoadingPage";
|
2021-06-19 15:20:43 +07:00
|
|
|
import ConsentView from "@views/LoginPortal/ConsentView/ConsentView";
|
|
|
|
import LoginPortal from "@views/LoginPortal/LoginPortal";
|
|
|
|
import SignOut from "@views/LoginPortal/SignOut/SignOut";
|
|
|
|
import ResetPasswordStep1 from "@views/ResetPassword/ResetPasswordStep1";
|
|
|
|
import ResetPasswordStep2 from "@views/ResetPassword/ResetPasswordStep2";
|
2021-01-02 17:58:24 +07:00
|
|
|
|
|
|
|
import "@fortawesome/fontawesome-svg-core/styles.css";
|
2020-04-26 05:12:55 +07:00
|
|
|
|
|
|
|
faConfig.autoAddCss = false;
|
2019-11-19 06:37:36 +07:00
|
|
|
|
2021-01-20 19:07:40 +07:00
|
|
|
function Theme() {
|
|
|
|
switch (getTheme()) {
|
|
|
|
case "dark":
|
|
|
|
return themes.Dark;
|
|
|
|
case "grey":
|
|
|
|
return themes.Grey;
|
2021-06-17 13:42:03 +07:00
|
|
|
case "auto":
|
|
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches ? themes.Dark : themes.Light;
|
2021-01-20 19:07:40 +07:00
|
|
|
default:
|
|
|
|
return themes.Light;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-21 07:35:30 +07:00
|
|
|
export interface Props {
|
|
|
|
nonce?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const App: React.FC<Props> = (props: Props) => {
|
2019-11-19 06:37:36 +07:00
|
|
|
const [notification, setNotification] = useState(null as Notification | null);
|
2021-06-17 13:42:03 +07:00
|
|
|
const [theme, setTheme] = useState(Theme());
|
2022-06-21 07:35:30 +07:00
|
|
|
|
|
|
|
const cache = createCache({
|
|
|
|
key: "authelia",
|
|
|
|
nonce: props.nonce,
|
|
|
|
prepend: true,
|
|
|
|
});
|
|
|
|
|
2021-06-17 13:42:03 +07:00
|
|
|
useEffect(() => {
|
|
|
|
if (getTheme() === "auto") {
|
|
|
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
// MediaQueryLists does not inherit from EventTarget in Internet Explorer
|
|
|
|
if (query.addEventListener) {
|
|
|
|
query.addEventListener("change", (e) => {
|
|
|
|
setTheme(e.matches ? themes.Dark : themes.Light);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, []);
|
2019-11-19 06:37:36 +07:00
|
|
|
return (
|
2022-06-21 07:35:30 +07:00
|
|
|
<CacheProvider value={cache}>
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<Suspense fallback={<BaseLoadingPage message={"Loading"} />}>
|
|
|
|
<CssBaseline />
|
|
|
|
<NotificationsContext.Provider value={{ notification, setNotification }}>
|
|
|
|
<Router basename={getBasePath()}>
|
|
|
|
<NotificationBar onClose={() => setNotification(null)} />
|
|
|
|
<Routes>
|
|
|
|
<Route path={ResetPasswordStep1Route} element={<ResetPasswordStep1 />} />
|
|
|
|
<Route path={ResetPasswordStep2Route} element={<ResetPasswordStep2 />} />
|
|
|
|
<Route path={RegisterWebauthnRoute} element={<RegisterWebauthn />} />
|
|
|
|
<Route path={RegisterOneTimePasswordRoute} element={<RegisterOneTimePassword />} />
|
|
|
|
<Route path={LogoutRoute} element={<SignOut />} />
|
|
|
|
<Route path={ConsentRoute} element={<ConsentView />} />
|
|
|
|
<Route
|
|
|
|
path={`${IndexRoute}*`}
|
|
|
|
element={
|
|
|
|
<LoginPortal
|
|
|
|
duoSelfEnrollment={getDuoSelfEnrollment()}
|
|
|
|
rememberMe={getRememberMe()}
|
|
|
|
resetPassword={getResetPassword()}
|
|
|
|
resetPasswordCustomURL={getResetPasswordCustomURL()}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
|
|
|
</Router>
|
|
|
|
</NotificationsContext.Provider>
|
|
|
|
</Suspense>
|
|
|
|
</ThemeProvider>
|
|
|
|
</CacheProvider>
|
2019-11-19 06:37:36 +07:00
|
|
|
);
|
2021-01-02 17:58:24 +07:00
|
|
|
};
|
2019-11-19 06:37:36 +07:00
|
|
|
|
|
|
|
export default App;
|