AeThex-OS/client/src/components/ProtectedRoute.tsx
sirpiglr 7f03ac1bb9 Add a virtual desktop environment with app management
Adds the AeThexOS virtual desktop page, including window management, app launching, and basic system utilities, along with updates to the protected route and authentication context.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 279f1558-c0e3-40e4-8217-be7e9f4c6eca
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 9aeffd21-c394-4a5b-a2cb-b0ba603639c1
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/b984cb14-1d19-4944-922b-bc79e821ed35/279f1558-c0e3-40e4-8217-be7e9f4c6eca/ogW6F7k
Replit-Helium-Checkpoint-Created: true
2025-12-16 06:30:51 +00:00

40 lines
974 B
TypeScript

import { useEffect, useRef } from "react";
import { useLocation } from "wouter";
import { useAuth } from "@/lib/auth";
interface ProtectedRouteProps {
children: React.ReactNode;
}
export function ProtectedRoute({ children }: ProtectedRouteProps) {
const { isAuthenticated, isLoading, user } = useAuth();
const [, setLocation] = useLocation();
const wasAuthenticated = useRef(false);
if (isAuthenticated) {
wasAuthenticated.current = true;
}
useEffect(() => {
if (!isLoading && !isAuthenticated) {
setLocation("/login");
}
}, [isLoading, isAuthenticated, setLocation]);
if (isLoading) {
if (wasAuthenticated.current || user) {
return <>{children}</>;
}
return (
<div className="min-h-screen bg-background flex items-center justify-center">
<div className="text-primary animate-pulse">Loading...</div>
</div>
);
}
if (!isAuthenticated) {
return null;
}
return <>{children}</>;
}