import React from "react"; import { Route, RouterProvider, createBrowserRouter, createRoutesFromElements, } from "react-router-dom"; import "./App.css"; import { AuthApi } from "./api/AuthApi"; import { ServerApi } from "./api/ServerApi"; import { CreateNetworkRoute, EditNetworkRoute, } from "./routes/EditNetworkRoute"; import { CreateVMRoute, EditVMRoute } from "./routes/EditVMRoute"; import { IsoFilesRoute } from "./routes/IsoFilesRoute"; import { NetworksListRoute } from "./routes/NetworksListRoute"; import { NotFoundRoute } from "./routes/NotFound"; import { SysInfoRoute } from "./routes/SysInfoRoute"; import { VMListRoute } from "./routes/VMListRoute"; import { VMRoute } from "./routes/VMRoute"; import { VNCRoute } from "./routes/VNCRoute"; import { LoginRoute } from "./routes/auth/LoginRoute"; import { OIDCCbRoute } from "./routes/auth/OIDCCbRoute"; import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage"; import { BaseLoginPage } from "./widgets/BaseLoginPage"; import { ViewNetworkRoute } from "./routes/ViewNetworkRoute"; import { VMXMLRoute } from "./routes/VMXMLRoute"; import { NetXMLRoute } from "./routes/NetXMLRoute"; import { HomeRoute } from "./routes/HomeRoute"; interface AuthContext { signedIn: boolean; setSignedIn: (signedIn: boolean) => void; } const AuthContextK = React.createContext(null); export function App() { const [signedIn, setSignedIn] = React.useState(AuthApi.SignedIn); const context: AuthContext = { signedIn: signedIn, setSignedIn: (s) => setSignedIn(s), }; const router = createBrowserRouter( createRoutesFromElements( signedIn || ServerApi.Config.auth_disabled ? ( }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ) : ( }> } /> } /> } /> ) ) ); return ( ); } export function useAuth(): AuthContext { return React.useContext(AuthContextK)!; }