91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
|
|
import { Sidebar } from "./components/Sidebar";
|
|
import { ChatInterface } from "./components/ChatInterface";
|
|
import { Dashboard } from "./pages/Dashboard";
|
|
import { Skills } from "./pages/Skills";
|
|
import { Settings } from "./pages/Settings";
|
|
import { Users } from "./pages/Users";
|
|
import { Login } from "./pages/Login";
|
|
import { useAuthStore } from "./store/authStore";
|
|
|
|
// Protected Route Component
|
|
function ProtectedRoute({ children, requireAdmin = false }: { children: React.ReactNode, requireAdmin?: boolean }) {
|
|
const { isAuthenticated, user } = useAuthStore();
|
|
|
|
if (!isAuthenticated) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
if (requireAdmin && !user?.is_admin) {
|
|
return <Navigate to="/" replace />;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|
|
|
|
function MainLayout({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<div className="flex h-screen w-full bg-background text-foreground overflow-hidden">
|
|
<Sidebar />
|
|
<main className="flex-1 flex flex-col overflow-hidden h-screen relative">
|
|
{children}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function App() {
|
|
return (
|
|
<BrowserRouter>
|
|
<Routes>
|
|
<Route path="/login" element={<Login />} />
|
|
|
|
{/* Protected Routes */}
|
|
<Route path="/" element={
|
|
<ProtectedRoute>
|
|
<MainLayout>
|
|
<div className="h-full overflow-hidden bg-white">
|
|
<ChatInterface />
|
|
</div>
|
|
</MainLayout>
|
|
</ProtectedRoute>
|
|
} />
|
|
|
|
<Route path="/dashboard" element={
|
|
<ProtectedRoute>
|
|
<MainLayout>
|
|
<Dashboard />
|
|
</MainLayout>
|
|
</ProtectedRoute>
|
|
} />
|
|
|
|
<Route path="/skills" element={
|
|
<ProtectedRoute>
|
|
<MainLayout>
|
|
<Skills />
|
|
</MainLayout>
|
|
</ProtectedRoute>
|
|
} />
|
|
|
|
<Route path="/settings" element={
|
|
<ProtectedRoute>
|
|
<MainLayout>
|
|
<Settings />
|
|
</MainLayout>
|
|
</ProtectedRoute>
|
|
} />
|
|
|
|
<Route path="/users" element={
|
|
<ProtectedRoute requireAdmin={true}>
|
|
<MainLayout>
|
|
<Users />
|
|
</MainLayout>
|
|
</ProtectedRoute>
|
|
} />
|
|
</Routes>
|
|
</BrowserRouter>
|
|
);
|
|
}
|
|
|
|
export default App;
|