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