blob: 76b663cb83c284b42d8f00f007e9f1d69266dcd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import type { ReactNode } from "react";
import { Redirect } from "wouter";
import { useAuth } from "../stores";
export interface ProtectedRouteProps {
children: ReactNode;
}
export function ProtectedRoute({ children }: ProtectedRouteProps) {
const { isAuthenticated, isLoading } = useAuth();
if (isLoading) {
return <div>Loading...</div>;
}
if (!isAuthenticated) {
return <Redirect to="/login" replace />;
}
return <>{children}</>;
}
|