turkmentv_front/components/lottery/auth/ProtectedRoute.tsx

29 lines
596 B
TypeScript
Raw Normal View History

2024-12-27 15:23:39 +00:00
'use client';
2024-12-23 19:13:36 +00:00
2024-12-27 15:23:39 +00:00
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useLotteryAuth } from '@/store/useLotteryAuth';
2024-12-23 19:13:36 +00:00
interface ProtectedRouteProps {
children: React.ReactNode;
}
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
const router = useRouter();
const { isAuthenticated } = useLotteryAuth();
useEffect(() => {
2024-12-27 15:23:39 +00:00
if (!isAuthenticated) {
router.replace('/lottery/auth');
2024-12-23 19:13:36 +00:00
}
2024-12-27 15:23:39 +00:00
}, [isAuthenticated, router]);
2024-12-23 19:13:36 +00:00
if (!isAuthenticated) {
2024-12-27 15:23:39 +00:00
return null;
2024-12-23 19:13:36 +00:00
}
return <>{children}</>;
};
export default ProtectedRoute;