diff options
Diffstat (limited to 'src/client/components/ProtectedRoute.tsx')
| -rw-r--r-- | src/client/components/ProtectedRoute.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/client/components/ProtectedRoute.tsx b/src/client/components/ProtectedRoute.tsx new file mode 100644 index 0000000..76b663c --- /dev/null +++ b/src/client/components/ProtectedRoute.tsx @@ -0,0 +1,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}</>; +} |
