diff --git a/src/components/app-shell.tsx b/src/components/app-shell.tsx index 5af4df4..17ebc13 100644 --- a/src/components/app-shell.tsx +++ b/src/components/app-shell.tsx @@ -1,27 +1,59 @@ +"use client" + import { Suspense, type ReactNode } from "react" - + import { AppSidebar } from "@/components/app-sidebar" import { AuthGuard } from "@/components/auth/auth-guard" -import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar" +import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar" +import { Skeleton } from "@/components/ui/skeleton" +import { useAuth } from "@/lib/auth-client" interface AppShellProps { header: ReactNode children: ReactNode } -export function AppShell({ header, children }: AppShellProps) { - return ( - - - +export function AppShell({ header, children }: AppShellProps) { + const { isLoading } = useAuth() + return ( + + + - {header} -
- {children} -
-
-
- ) -} + {isLoading ? ( +
+
+ +
+ + +
+
+ +
+ ) : ( + header + )} +
+ {isLoading ? ( +
+
+
+ + +
+
+
+ +
+
+ ) : ( + children + )} +
+
+
+ ) +} diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index cc2dce2..0bf23f4 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -22,6 +22,7 @@ import { ShieldCheck, } from "lucide-react" import { usePathname } from "next/navigation" +import Link from "next/link" import { SearchForm } from "@/components/search-form" import { VersionSwitcher } from "@/components/version-switcher" @@ -240,7 +241,7 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - + {item.icon ? : null} {item.title} ) { > - + {isExpanded ? childItems.map((child) => ( - + {child.icon ? : null} {child.title} - + )) @@ -280,10 +281,10 @@ export function AppSidebar({ ...props }: React.ComponentProps) { return ( - + {item.icon ? : null} {item.title} - + ) diff --git a/src/components/auth/auth-guard.tsx b/src/components/auth/auth-guard.tsx index 07d2c4d..7092d5e 100644 --- a/src/components/auth/auth-guard.tsx +++ b/src/components/auth/auth-guard.tsx @@ -1,29 +1,14 @@ "use client" -import { useEffect } from "react" -import { usePathname, useRouter, useSearchParams } from "next/navigation" - import { useAuth } from "@/lib/auth-client" +// Melhor abordagem: sem redirecionamentos no cliente. +// O middleware (middleware.ts) já gateia todas as rotas não públicas com base no cookie/sessão. +// Mantemos este componente como no-op para evitar qualquer flash de /login. export function AuthGuard() { - const { session, isLoading } = useAuth() - const router = useRouter() - const pathname = usePathname() - const searchParams = useSearchParams() - - useEffect(() => { - if (isLoading) return - if (session?.user) return - - const search = searchParams?.toString() - const callbackUrl = pathname - ? search && search.length > 0 - ? `${pathname}?${search}` - : pathname - : undefined - const nextUrl = callbackUrl ? `/login?callbackUrl=${encodeURIComponent(callbackUrl)}` : "/login" - router.replace(nextUrl) - }, [isLoading, session?.user, pathname, searchParams, router]) - + // Podemos, se quisermos, ler isLoading para futuramente exibir um skeleton. + // No momento, não fazemos nada aqui. + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { isLoading } = useAuth() return null }