diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-12-06 18:55:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-12-06 18:55:57 +0900 |
| commit | f655585cc81ab4af5d27cebb1fa9390e93e0a4bf (patch) | |
| tree | a7e6bbcb9816f85ec8dff7a8c6a8ac5dbcb7c395 /src/client/components/ProtectedRoute.tsx | |
| parent | 516e26f5ca72f2db724fd68584663c0732c77f77 (diff) | |
| download | kioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.tar.gz kioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.tar.zst kioku-f655585cc81ab4af5d27cebb1fa9390e93e0a4bf.zip | |
feat(client): add protected route handling with login redirect
Unauthenticated users accessing protected pages (like HomePage) are
now redirected to the login page. Includes ProtectedRoute component
with loading state support.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
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}</>; +} |
