aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/components/ProtectedRoute.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/components/ProtectedRoute.tsx')
-rw-r--r--src/client/components/ProtectedRoute.tsx21
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}</>;
+}