🚧 WIP
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { NavLink, Navigate, Route, Routes } from "react-router-dom";
|
||||
import { useAuth } from "./auth";
|
||||
import { LoginPage } from "./pages/Login";
|
||||
import { ClientsPage } from "./pages/Clients";
|
||||
import { RolesPage } from "./pages/Roles";
|
||||
import { GroupsPage } from "./pages/Groups";
|
||||
import { BrokerConfigPage } from "./pages/BrokerConfig";
|
||||
|
||||
function Layout({ children }: { children: React.ReactNode }) {
|
||||
const { session, logout } = useAuth();
|
||||
return (
|
||||
<div className="layout">
|
||||
<aside className="sidebar">
|
||||
<h1>MQTT Management</h1>
|
||||
<nav>
|
||||
<NavLink to="/clients">Clients</NavLink>
|
||||
<NavLink to="/groups">Groups</NavLink>
|
||||
<NavLink to="/roles">Roles & ACLs</NavLink>
|
||||
<NavLink to="/broker">Broker configuration</NavLink>
|
||||
</nav>
|
||||
<p style={{ marginTop: "2rem", fontSize: "0.8rem", opacity: 0.7 }}>
|
||||
{session?.username} ({session?.role})
|
||||
</p>
|
||||
<button onClick={() => void logout()}>Sign out</button>
|
||||
</aside>
|
||||
<main className="content">{children}</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Protected({ children }: { children: React.ReactNode }) {
|
||||
const { session, loading } = useAuth();
|
||||
if (loading) return <p>Loading…</p>;
|
||||
if (!session) return <Navigate to="/login" replace />;
|
||||
return <Layout>{children}</Layout>;
|
||||
}
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route
|
||||
path="/clients"
|
||||
element={
|
||||
<Protected>
|
||||
<ClientsPage />
|
||||
</Protected>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/groups"
|
||||
element={
|
||||
<Protected>
|
||||
<GroupsPage />
|
||||
</Protected>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/roles"
|
||||
element={
|
||||
<Protected>
|
||||
<RolesPage />
|
||||
</Protected>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/broker"
|
||||
element={
|
||||
<Protected>
|
||||
<BrokerConfigPage />
|
||||
</Protected>
|
||||
}
|
||||
/>
|
||||
<Route path="/" element={<Navigate to="/clients" replace />} />
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user