import { useEffect, useState } from "react"; import { Navigate, Route, Routes } from "react-router-dom"; import { api } from "./api"; import { DirtyProvider } from "./DirtyContext"; import Layout from "./components/Layout"; import Login from "./pages/Login"; import Dashboard from "./pages/Dashboard"; import Users from "./pages/Users"; import Samba from "./pages/Samba"; import Nfs from "./pages/Nfs"; import Log from "./pages/Log"; import Settings from "./pages/Settings"; import Files from "./pages/Files"; type AuthState = { loading: boolean; authenticated: boolean; username: string }; export default function App() { const [auth, setAuth] = useState({ loading: true, authenticated: false, username: "" }); useEffect(() => { api .status() .then((res) => setAuth({ loading: false, authenticated: res.authenticated, username: res.username })) .catch(() => setAuth({ loading: false, authenticated: false, username: "" })); }, []); if (auth.loading) { return
Cargando...
; } if (!auth.authenticated) { return ( setAuth({ loading: false, authenticated: true, username })} />} /> } /> ); } return ( setAuth({ loading: false, authenticated: false, username: "" })} /> } > } /> } /> } /> } /> } /> } /> } /> } /> ); }