'use client'; import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { fetchCurrentUser, checkDevMode } from '@/store/slices/authSlice'; import { RootState, AppDispatch } from '@/store/store'; import { usePathname, useRouter } from 'next/navigation'; const PUBLIC_PATHS = ['/login']; export function AuthGuard({ children }: { children: React.ReactNode }) { const dispatch = useDispatch(); const { isLoading, isAuthenticated } = useSelector( (state: RootState) => state.auth ); const pathname = usePathname(); const router = useRouter(); useEffect(() => { dispatch(fetchCurrentUser()); dispatch(checkDevMode()); }, [dispatch]); // Allow public paths without auth if (PUBLIC_PATHS.includes(pathname)) { return <>{children}; } if (isLoading) { return (

OLIVER DeckForge

Loading...

); } if (!isAuthenticated) { router.push('/login'); return null; } return <>{children}; }