2026-01-06 14:46:23 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
2026-02-28 23:35:32 +05:45
|
|
|
import { useAuth } from "@/contexts/AuthContext";
|
2025-01-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
const Index = () => {
|
2026-01-06 14:46:23 +00:00
|
|
|
const navigate = useNavigate();
|
2026-02-28 23:35:32 +05:45
|
|
|
const { isAuthenticated, isLoading } = useAuth();
|
2026-01-06 14:46:23 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-02-28 23:35:32 +05:45
|
|
|
if (isLoading) return; // Wait for auth check to complete
|
|
|
|
|
|
|
|
|
|
if (isAuthenticated) {
|
|
|
|
|
navigate("/profile");
|
|
|
|
|
} else {
|
|
|
|
|
navigate("/login");
|
|
|
|
|
}
|
|
|
|
|
}, [isLoading, isAuthenticated, navigate]);
|
2026-01-06 14:46:23 +00:00
|
|
|
|
|
|
|
|
return null;
|
2025-01-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Index;
|