fix(dashboard): 거래처(USER) 진입 시 /m/orders/new 로 자동 이동
Deploy momo-erp / deploy (push) Failing after 3m42s
Deploy momo-erp / deploy (push) Failing after 3m42s
대시보드는 관리자 전용. USER 가 직접 URL 로 진입해도 즉시 출고 요청 화면으로 리다이렉트되게 차단. (메뉴 매핑 없어도 직접 URL 접근 방지) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ShoppingCart, Package, ClipboardList, TrendingUp, AlertTriangle, ArrowRight } from "lucide-react";
|
||||
|
||||
type DashboardData =
|
||||
@@ -29,19 +30,25 @@ const STATUS_COLOR: Record<string, string> = {
|
||||
};
|
||||
|
||||
export default function MomoDashboard() {
|
||||
const [role, setRole] = useState<"USER" | "ADMIN">("USER");
|
||||
const router = useRouter();
|
||||
const [role, setRole] = useState<"USER" | "ADMIN" | null>(null);
|
||||
const [data, setData] = useState<DashboardData | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/auth/me").then((r) => r.json()).then((d) => {
|
||||
const u = d?.user;
|
||||
const isAdmin = u?.role === "ADMIN" || u?.isAdmin === true || u?.userType === "A";
|
||||
setRole(isAdmin ? "ADMIN" : "USER");
|
||||
if (!isAdmin) {
|
||||
// 일반 구매자는 대시보드 대상이 아님 → 출고 요청 화면으로 즉시 이동
|
||||
router.replace("/m/orders/new");
|
||||
return;
|
||||
}
|
||||
setRole("ADMIN");
|
||||
fetch("/api/m/dashboard").then((r) => r.json()).then(setData);
|
||||
});
|
||||
fetch("/api/m/dashboard").then((r) => r.json()).then(setData);
|
||||
}, []);
|
||||
}, [router]);
|
||||
|
||||
if (!data) return <div className="text-slate-500">불러오는 중...</div>;
|
||||
if (role !== "ADMIN" || !data) return <div className="text-slate-500">불러오는 중...</div>;
|
||||
|
||||
if (role === "USER") {
|
||||
const d = data as Extract<DashboardData, { recent: unknown[] }>;
|
||||
|
||||
Reference in New Issue
Block a user