mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-08-09 17:59:24 +00:00
cba930e4d3
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/54918520-d42c-44cd-b4f4-9e5a42eb5be1.jpg
34 lines
706 B
TypeScript
34 lines
706 B
TypeScript
import { useAuth } from "@/hooks/use-auth";
|
|
import { Loader2 } from "lucide-react";
|
|
import { Redirect, Route } from "wouter";
|
|
|
|
export function ProtectedRoute({
|
|
path,
|
|
component: Component,
|
|
}: {
|
|
path: string;
|
|
component: () => React.JSX.Element;
|
|
}) {
|
|
const { user, isLoading } = useAuth();
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<Route path={path}>
|
|
<div className="flex items-center justify-center min-h-screen">
|
|
<Loader2 className="h-8 w-8 animate-spin text-border" />
|
|
</div>
|
|
</Route>
|
|
);
|
|
}
|
|
|
|
if (!user) {
|
|
return (
|
|
<Route path={path}>
|
|
<Redirect to="/auth" />
|
|
</Route>
|
|
);
|
|
}
|
|
|
|
return <Route path={path} component={Component} />;
|
|
}
|