TorbatYar/frontend/components/AuthGuard.tsx
Mortezakoohjani 800b0ba2c5 Deploy TorbatYar for torbatyar.ir with nginx multi-tenant routing.
Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-21 21:43:33 +03:30

27 lines
731 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useAuth } from "@/hooks/useAuth";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
export function AuthGuard({ children }: { children: React.ReactNode }) {
const { isAuthenticated, loading, login } = useAuth();
const router = useRouter();
useEffect(() => {
if (!loading && !isAuthenticated) {
login();
}
}, [loading, isAuthenticated, login]);
if (loading) {
return <p className="text-sm text-gray-500">در حال بررسی احراز هویت...</p>;
}
if (!isAuthenticated) {
return <p className="text-sm text-gray-500">در حال هدایت به صفحه ورود...</p>;
}
return <>{children}</>;
}