50db71843b
- 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.
30 lines
686 B
TypeScript
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;
|