import React from "react"; import { Route, RouterProvider, createBrowserRouter, createRoutesFromElements, } from "react-router-dom"; import "./App.css"; import { AuthApi } from "./api/AuthApi"; import { DeleteAccountRoute } from "./routes/DeleteAccountRoute"; import { FamiliesListRoute } from "./routes/FamiliesListRoute"; import { NotFoundRoute } from "./routes/NotFound"; import { ProfileRoute } from "./routes/ProfileRoute"; import { LoginRoute } from "./routes/auth/LoginRoute"; import { NewAccountRoute } from "./routes/auth/NewAccountRoute"; import { OIDCCbRoute } from "./routes/auth/OIDCCbRoute"; import { PasswordForgottenRoute } from "./routes/auth/PasswordForgottenRoute"; import { ResetPasswordRoute } from "./routes/auth/ResetPasswordRoute"; import { FamilyHomeRoute } from "./routes/family/FamilyHomeRoute"; import { FamilyCreateMemberRoute, FamilyEditMemberRoute, FamilyMemberRoute, } from "./routes/family/FamilyMemberRoute"; import { FamilySettingsRoute } from "./routes/family/FamilySettingsRoute"; import { FamilyUsersListRoute } from "./routes/family/FamilyUsersListRoute"; import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage"; import { BaseFamilyRoute } from "./widgets/BaseFamilyRoute"; import { BaseLoginPage } from "./widgets/BaseLoginpage"; import { FamilyMembersListRoute } from "./routes/family/FamilyMembersListRoute"; interface AuthContext { signedIn: boolean; setSignedIn: (signedIn: boolean) => void; } const AuthContextK = React.createContext(null); /** * Core app */ export function App(): React.ReactElement { const [signedIn, setSignedIn] = React.useState(AuthApi.SignedIn); const context: AuthContext = { signedIn: signedIn, setSignedIn: (s) => setSignedIn(s), }; const router = createBrowserRouter( createRoutesFromElements( <> } /> {signedIn ? ( }> } /> } /> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> ) : ( }> } /> } /> } /> } /> } /> } /> )} ) ); return ( ); } export function useAuth(): AuthContext { return React.useContext(AuthContextK)!; }