Initial commit: Mana Collection dashboards (Next.js).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-07 20:50:24 +03:30
co-authored by Cursor
commit 18b29f5b62
95 changed files with 16414 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
"use client";
import { useEffect } from "react";
import { usePathname, useRouter } from "next/navigation";
import { useAuth } from "@/lib/auth";
const PUBLIC_PATHS = ["/login", "/coming-soon"];
const WEBSITE_HOSTS = new Set([
"mana-collection.com",
"www.mana-collection.com",
]);
export default function RequireStoreAuth({
children,
}: {
children: React.ReactNode;
}) {
const { user, loading } = useAuth();
const pathname = usePathname();
const router = useRouter();
const host =
typeof window !== "undefined"
? window.location.hostname.toLowerCase()
: "";
const onWebsite = WEBSITE_HOSTS.has(host);
const isPublic =
onWebsite ||
PUBLIC_PATHS.some((p) => pathname === p || pathname.startsWith(`${p}/`));
useEffect(() => {
if (loading || isPublic) return;
if (!user) {
router.replace("/login");
return;
}
if (user.role === "CUSTOMER") {
router.replace("/login?as=customer");
}
}, [user, loading, isPublic, router]);
if (isPublic) return <>{children}</>;
if (loading) {
return (
<div className="flex min-h-dvh items-center justify-center text-sm text-muted">
در حال بارگذاری…
</div>
);
}
if (!user || user.role === "CUSTOMER") return null;
return <>{children}</>;
}