blob: e03a4f0ad6e0ff48fe96da1237fc124d38d663d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import type { ReactNode } from "react";
import { Redirect } from "wouter";
import { useAuth } from "../contexts/AuthContext";
interface Props {
children: ReactNode;
}
export function ProtectedRoute({ children }: Props) {
const { isLoggedIn, isLoading } = useAuth();
if (isLoading) {
return (
<div className="flex justify-center items-center min-h-screen">
Loading...
</div>
);
}
if (!isLoggedIn) {
return <Redirect to="/login" />;
}
return <>{children}</>;
}
|