- Backend: POST /suggestions (público) + GET /suggestions (JWT admin) - Admin: página pública /sugerencias con formulario de sugerencias - schema.prisma: modelo suggestions - AuthGuard + Sidebar: /sugerencias como ruta pública Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
781 B
TypeScript
24 lines
781 B
TypeScript
'use client';
|
|
|
|
import { useAuth } from '@/lib/auth';
|
|
import { usePathname, useRouter } from 'next/navigation';
|
|
import { useEffect, type ReactNode } from 'react';
|
|
|
|
export default function AuthGuard({ children }: { children: ReactNode }) {
|
|
const { user, isLoading } = useAuth();
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
|
|
const isLoginPage = pathname === '/login' || pathname === '/sugerencias';
|
|
|
|
useEffect(() => {
|
|
if (!isLoginPage && !isLoading && !user) router.replace('/login');
|
|
}, [user, isLoading, router, isLoginPage]);
|
|
|
|
if (isLoginPage) return <>{children}</>;
|
|
if (isLoading) return <div className="flex h-screen items-center justify-center text-muted-foreground">Cargando...</div>;
|
|
if (!user) return null;
|
|
|
|
return <>{children}</>;
|
|
}
|