Files
nirvana-v3/packages/desktop/src/components/ProtectedRoute/index.tsx
T

27 lines
646 B
TypeScript

import Login from "../../pages/Login";
import SkeletonLoader from "../loading/skeleton";
import { useEffect } from "react";
import { useGetUserDetails } from "../../controller/index";
export default function ProtectedRoute({
children,
}: {
children?: React.ReactNode;
}) {
const { data, isLoading, isError, refetch } = useGetUserDetails();
if (isLoading)
return (
<div className="container h-screen w-screen">
<SkeletonLoader />
</div>
);
if (isError) {
return <Login onReady={() => refetch()} />;
}
// if we can successfully get user details, we are good to continue
return <>{children}</>;
}