Add admin login page and required logic

This commit is contained in:
Muhtadee Taron
2025-07-04 17:55:49 +06:00
parent ac49576b9b
commit 6b2690d1df
19 changed files with 781 additions and 37 deletions

View File

@ -0,0 +1,27 @@
"use client";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { useAuth } from "@/context/AuthContext";
import LoadingSpinner from "./LoadingSpinner";
export default function ProtectedRoute({
children,
}: {
children: React.ReactNode;
}) {
const { authState } = useAuth();
const router = useRouter();
useEffect(() => {
if (!authState.isLoading && !authState.isAuthenticated) {
router.push("/login");
}
}, [authState.isAuthenticated, authState.isLoading, router]);
if (authState.isLoading) {
return <LoadingSpinner />;
}
return authState.isAuthenticated ? children : null;
}