import { StrictMode, useEffect, useState } from "react"; import { createRoot } from "react-dom/client"; import { createBrowserRouter, RouterProvider, redirect, Navigate } from "react-router-dom"; import App from "./pages/App"; import "./index.css"; import Conversation from "./pages/conversation/App"; import { isAuthenticated } from "./lib/login"; import LoginPage, { EmailVerificationForm } from "./pages/auth/login"; import Home from "./pages/home/home" import React from "react"; import RegisterPage from "./pages/auth/signup"; import SubscriptionSuccess from "./pages/sucess/success"; import { Rocket } from "lucide-react"; import EmailVerificationPage from "./pages/auth/emailverification"; import PricingPage from "./pages/pricing/pricing"; import SubscriptionDetail from "./pages/subscriptionDetail/App"; // Componente para proteger rotas const ProtectedRoute = ({ children }: { children: JSX.Element }) => { const [loading, setLoading] = useState(true); const [auth, setAuth] = useState(false); useEffect(() => { const checkAuth = async () => { const result = await isAuthenticated(); setAuth(result); setLoading(false); }; checkAuth(); }, []); {/**if (loading) { return
SalesPulse
; // ou um spinner } **/} return auth ? children : ; }; const router = createBrowserRouter([ { path: "/", element: , }, { path:"/emailverification", element: , }, { path:"/pricing", element: }, { path: "/login", element: , loader: async () => { if (await isAuthenticated()) { return redirect("/dashboard"); } return null; } }, { path: "/register", element: , loader: async () => { if (await isAuthenticated()) { return redirect("/dashboard"); } return null; } }, { path: "/dashboard", element: ( ), loader: () => { if (!isAuthenticated()) { return redirect("/login"); } return null; } }, { path: "/subscription/success", element: , loader: () => { if (!isAuthenticated()) { return redirect("/login"); } return null; } }, { path: "/subscription/detail", element: , loader: () => { if (!isAuthenticated()) { return redirect("/login"); } return null; } }, // Rota para erros 404 { path: "*", element:
Página não encontrada
} ]); createRoot(document.getElementById("root")!).render( );