TorbatYar/frontend/components/AuthGuard.tsx
Mortezakoohjani 12c8615615 Ship enterprise Accounting FE/API with CRUD parity and production wiring.
Adds accounting-service PATCH/archive, fiscal helpers, COA templates and setup status, plus SuperApp Accounting UI (DS, scoreboard, masters, vouchers, ledger, ops modules) with session refresh and HTTPS public API URLs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 15:26:43 +03:30

27 lines
795 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(typeof window !== "undefined" ? window.location.href : undefined);
}
}, [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}</>;
}