aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/ProtectedRoute.tsx
blob: 5f564a0057b408419c1734c1908036bfc97c12ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Redirect } from "wouter";
import { useAuth } from "../hooks/useAuth";

export default function ProtectedRoute({
  children,
}: {
  children: React.ReactNode;
}) {
  const { isLoggedIn, isLoading } = useAuth();

  if (isLoading) {
    return null;
  }

  if (!isLoggedIn) {
    return <Redirect to="/login" />;
  }

  return <>{children}</>;
}