|
1 | | -import { useState, useEffect } from "react"; |
2 | | -import { Navigate, Route, Routes } from "react-router-dom"; |
3 | | -import LandingPage from "./pages/dashboard/LandingPage"; |
4 | | -import Dashboard from "./pages/dashboard/Dashboard"; |
5 | | -import NotFound from "./not_found"; |
6 | | -import Loading from "./Loading"; |
7 | | -import LoginPage from "./pages/login/LoginPage"; |
8 | | -import RegisterPage from "./pages/register/RegisterPage"; |
9 | | -import AuthCallback from "./pages/auth/AuthCallback"; |
10 | | -import { useAuth } from "@/context/AuthContext"; |
11 | | - |
12 | | -function ProtectedRoute({ children }: { children: React.ReactNode }) { |
13 | | - const { user, isLoading } = useAuth(); |
14 | | - if (isLoading) return <Loading />; |
15 | | - if (!user) return <Navigate to="/login" replace />; |
16 | | - return <>{children}</>; |
17 | | -} |
18 | | - |
19 | | -function PublicRoute({ children }: { children: React.ReactNode }) { |
20 | | - const { user, isLoading } = useAuth(); |
21 | | - if (isLoading) return <Loading />; |
22 | | - if (user) return <Navigate to="/app" replace />; |
23 | | - return <>{children}</>; |
24 | | -} |
25 | | - |
26 | | -function App() { |
27 | | - const [appCarregando, setAppCarregando] = useState(true); |
28 | | - |
29 | | - useEffect(() => { |
30 | | - const timer = setTimeout(() => { |
31 | | - setAppCarregando(false); |
32 | | - }, 2000); |
33 | | - |
34 | | - return () => clearTimeout(timer); |
35 | | - }, []); |
36 | | - |
37 | | - if (appCarregando) { |
38 | | - return <Loading />; |
39 | | - } |
40 | | - |
41 | | - return ( |
42 | | - <Routes> |
43 | | - <Route path="/" element={<LandingPage />} /> |
44 | | - <Route |
45 | | - path="/app" |
46 | | - element={ |
47 | | - <ProtectedRoute> |
48 | | - <Dashboard /> |
49 | | - </ProtectedRoute> |
50 | | - } |
51 | | - /> |
52 | | - <Route path="/login" element={<PublicRoute><LoginPage /></PublicRoute>} /> |
53 | | - <Route path="/register" element={<PublicRoute><RegisterPage /></PublicRoute>} /> |
54 | | - <Route path="/auth/callback" element={<AuthCallback />} /> |
55 | | - <Route path="*" element={<NotFound />} /> |
56 | | - </Routes> |
57 | | - ); |
58 | | -} |
59 | | - |
60 | | -export default App; |
| 1 | +export { default } from "@/app/App"; |
0 commit comments