summaryrefslogtreecommitdiff
path: root/makima/frontend/src/components/ProtectedRoute.tsx
blob: 32ac592677699f5d5a95460cee19ebef6dd1fc99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Navigate } from "react-router";
import { useAuth } from "../contexts/AuthContext";

interface ProtectedRouteProps {
  children: React.ReactNode;
}

export function ProtectedRoute({ children }: ProtectedRouteProps) {
  const { isAuthenticated, isLoading, isAuthConfigured } = useAuth();

  // Show loading state while checking auth
  if (isLoading) {
    return (
      <div className="min-h-screen bg-black text-white flex items-center justify-center">
        <div className="text-zinc-400">Loading...</div>
      </div>
    );
  }

  // If auth is configured but user is not authenticated, redirect to login
  if (isAuthConfigured && !isAuthenticated) {
    return <Navigate to="/login" replace />;
  }

  return <>{children}</>;
}