2026-03-22 11:19:41 +08:00
|
|
|
import { BrowserRouter, Routes, Route, Navigate, useLocation } from "react-router-dom";
|
2026-03-22 03:01:23 +08:00
|
|
|
import { HomePage } from "./pages/home-page";
|
2026-03-22 03:05:42 +08:00
|
|
|
import { LoginPage } from "./pages/login-page";
|
|
|
|
|
import { ToolPage } from "./pages/tool-page";
|
2026-03-22 04:42:31 +08:00
|
|
|
import { AutomatePage } from "./pages/automate-page";
|
|
|
|
|
import { FullscreenGridPage } from "./pages/fullscreen-grid-page";
|
|
|
|
|
import { KeyboardShortcutProvider } from "./components/common/keyboard-shortcut-provider";
|
2026-03-22 11:19:41 +08:00
|
|
|
import { useAuth } from "./hooks/use-auth";
|
|
|
|
|
|
|
|
|
|
function AuthGuard({ children }: { children: React.ReactNode }) {
|
|
|
|
|
const { loading, authEnabled, isAuthenticated } = useAuth();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
// Don't guard the login page itself
|
|
|
|
|
if (location.pathname === "/login") {
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex h-screen items-center justify-center bg-background text-foreground">
|
|
|
|
|
<div className="text-center space-y-3">
|
|
|
|
|
<div className="h-8 w-8 border-2 border-primary border-t-transparent rounded-full animate-spin mx-auto" />
|
|
|
|
|
<p className="text-sm text-muted-foreground">Loading...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (authEnabled && !isAuthenticated) {
|
|
|
|
|
return <Navigate to="/login" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|
2026-03-22 02:57:49 +08:00
|
|
|
|
|
|
|
|
export function App() {
|
|
|
|
|
return (
|
|
|
|
|
<BrowserRouter>
|
2026-03-22 04:42:31 +08:00
|
|
|
<KeyboardShortcutProvider>
|
2026-03-22 11:19:41 +08:00
|
|
|
<AuthGuard>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/login" element={<LoginPage />} />
|
|
|
|
|
<Route path="/automate" element={<AutomatePage />} />
|
|
|
|
|
<Route path="/fullscreen" element={<FullscreenGridPage />} />
|
|
|
|
|
<Route path="/:toolId" element={<ToolPage />} />
|
|
|
|
|
<Route path="/" element={<HomePage />} />
|
|
|
|
|
</Routes>
|
|
|
|
|
</AuthGuard>
|
2026-03-22 04:42:31 +08:00
|
|
|
</KeyboardShortcutProvider>
|
2026-03-22 02:57:49 +08:00
|
|
|
</BrowserRouter>
|
|
|
|
|
);
|
|
|
|
|
}
|