aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/PublicOnlyRoute.tsx
blob: 7b3ef9d20a10a7412fa6911a21f794297806cc36 (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}</>;
}