diff --git a/src/App.tsx b/src/App.tsx index 3c1d150..94773a1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import { Toaster } from "@/components/ui/sonner"; import { TooltipProvider } from "@/components/ui/tooltip"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { BrowserRouter, Routes, Route } from "react-router-dom"; +import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom"; import { useEffect } from "react"; import { supabase } from "@/integrations/supabase/client"; import { useAuthStore } from "@/stores/authStore"; @@ -63,22 +63,20 @@ function App() { } /> {/* Rotas protegidas */} - }> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> {/* Rota 404 */} diff --git a/src/components/auth/ProtectedRoute.tsx b/src/components/auth/ProtectedRoute.tsx index 865d941..764147d 100644 --- a/src/components/auth/ProtectedRoute.tsx +++ b/src/components/auth/ProtectedRoute.tsx @@ -2,7 +2,7 @@ import { ReactNode, useEffect, useState } from 'react'; import { Navigate, useLocation } from 'react-router-dom'; import LoadingState from '../whatsapp/LoadingState'; -import { authStore } from '@/stores/authStore'; +import { useAuthStore } from '@/stores/authStore'; import { supabase } from '@/integrations/supabase/client'; import { Session } from '@supabase/supabase-js'; import { useProfileCompletion } from '@/hooks/useProfileCompletion'; @@ -16,9 +16,9 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { const [isLoading, setIsLoading] = useState(true); const location = useLocation(); - const setLoggedIn = authStore((state) => state.setLoggedIn); - const setUser = authStore((state) => state.setUser); - const isProfileComplete = authStore((state) => state.isProfileComplete); + const setLoggedIn = useAuthStore((state) => state.setLoggedIn); + const setUser = useAuthStore((state) => state.setUser); + const isProfileComplete = useAuthStore((state) => state.isProfileComplete); // Hook para verificar completude do perfil const { isChecking } = useProfileCompletion(session?.user?.email || ''); diff --git a/src/components/layout/Layout.tsx b/src/components/layout/Layout.tsx index 0ea830d..1b3087f 100644 --- a/src/components/layout/Layout.tsx +++ b/src/components/layout/Layout.tsx @@ -58,7 +58,7 @@ export default function Layout({ children, useModernSidebar = true }: LayoutProp : 'relative' } `}> - + {/* Main content */} diff --git a/src/stores/authStore.ts b/src/stores/authStore.ts index 78bf4f7..6723a93 100644 --- a/src/stores/authStore.ts +++ b/src/stores/authStore.ts @@ -4,17 +4,21 @@ import { create } from 'zustand'; interface AuthState { isLoggedIn: boolean; user: { id: string } | null; + session: any; isProfileComplete: boolean; setLoggedIn: (status: boolean) => void; setUser: (user: { id: string } | null) => void; + setSession: (session: any) => void; setProfileComplete: (complete: boolean) => void; } -export const authStore = create((set) => ({ +export const useAuthStore = create((set) => ({ isLoggedIn: false, user: null, + session: null, isProfileComplete: true, // Default true para não afetar usuários existentes setLoggedIn: (status) => set({ isLoggedIn: status }), setUser: (user) => set({ user }), + setSession: (session) => set({ session }), setProfileComplete: (complete) => set({ isProfileComplete: complete }), }));