aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/PublicOnlyRoute.tsx
blob: e28f5ee088040827f621c8d6e27b5c26140f9dfc (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 PublicOnlyRoute({
  children,
}: {
  children: React.ReactNode;
}) {
  const { isLoggedIn, isLoading } = useAuth();

  if (isLoading) {
    return null;
  }

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

  return <>{children}</>;
}