blob: 0cfef42f3ae4254686dd1961dc67942614c49c27 (
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
26
27
28
29
30
31
32
|
import type { ReactNode } from "react";
import { Redirect } from "wouter";
import { useAuth } from "../contexts/AuthContext";
interface Props {
children: ReactNode;
}
export function ProtectedRoute({ children }: Props) {
const { user, isLoading } = useAuth();
if (isLoading) {
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
minHeight: "100vh",
}}
>
Loading...
</div>
);
}
if (!user) {
return <Redirect to="/login" />;
}
return <>{children}</>;
}
|