PatientProTokenRepository/src/app/page.js
2025-04-23 11:50:43 +05:30

38 lines
1.1 KiB
JavaScript

// src/app/page.js
"use client"; // Mark this as a client component
import { useRouter } from "next/navigation";
import { useAuth } from "./context/AuthContext"; // Import useAuth
import { useEffect } from "react"; // Import useEffect
export default function Home() {
const router = useRouter();
const { isAuthenticated, loading } = useAuth();
useEffect(() => {
if (!loading) {
if (isAuthenticated) {
router.push("/dashboard");
} else {
router.push("/signup");
}
}
}, [isAuthenticated, loading, router]);
if (loading) {
return (
<div className="flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-900">
<div className="text-center">
{/* Spinner */}
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 dark:border-gray-100 mx-auto"></div>
{/* Loading Text */}
<p className="mt-4 text-lg font-semibold text-gray-900 dark:text-gray-100 ">
Loading...
</p>
</div>
</div>
);
}
return null; // No need to render anything here
}