aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/ProtectedRoute.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/ProtectedRoute.tsx')
-rw-r--r--frontend/src/components/ProtectedRoute.tsx32
1 files changed, 32 insertions, 0 deletions
diff --git a/frontend/src/components/ProtectedRoute.tsx b/frontend/src/components/ProtectedRoute.tsx
new file mode 100644
index 0000000..0cfef42
--- /dev/null
+++ b/frontend/src/components/ProtectedRoute.tsx
@@ -0,0 +1,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}</>;
+}