aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/ProtectedRoute.tsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-06 04:10:55 +0900
committernsfisis <nsfisis@gmail.com>2025-11-08 05:04:02 +0900
commite0cc2915f22fe74d5be9e8f51d6b73437192e0ba (patch)
treee2e27e3cba8b5e7205732eef7b6df9789e83396f /frontend/src/components/ProtectedRoute.tsx
parentba1e0c904f810193f25d4f88cc2bb168f1d625fe (diff)
downloadfeedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.tar.gz
feedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.tar.zst
feedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.zip
feat: Support multi-user
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}</>;
+}