Files
tm_panel/src/contexts/Auth-guard.ctx.tsx
T
AmirReza Jamali 50db71843b refactor(Loading): update Loading component import paths
- Changed import paths for the Loading component from "@/app/loading" to "@/components/loading" across multiple files to maintain consistency and improve modularity.
- Removed the Loading component definition from loading.tsx, simplifying the file structure.
2026-04-13 08:07:43 +03:30

30 lines
686 B
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { useEffect, ReactNode } from "react";
import { useUser } from "./";
import Loading from "@/components/loading";
interface AuthGuardProps {
children: ReactNode;
}
const AuthGuard = ({ children }: AuthGuardProps): React.ReactNode => {
const { isAuthenticated, isLoading } = useUser();
const router = useRouter();
useEffect(() => {
if (!isLoading && !isAuthenticated) {
router.push("/auth/sign-in");
}
}, [isLoading, isAuthenticated, router]);
if (isLoading || !isAuthenticated) {
return <Loading className="min-h-svh flex-none" />;
}
return children;
};
export default AuthGuard;