From d9415a9b37b28f307ff9088b8b34bcdf10056c7d Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 15 Jun 2025 23:42:36 +0800 Subject: [PATCH] . --- apps/blogai/components/header.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/blogai/components/header.tsx b/apps/blogai/components/header.tsx index b3c6ed3..a0520aa 100644 --- a/apps/blogai/components/header.tsx +++ b/apps/blogai/components/header.tsx @@ -389,6 +389,13 @@ export function DetailPageHeader({ data }: { data: any }) { const userData = JSON.parse(localStorage.getItem("UserData") || "null"); const userName = userData?.user_name; + const id = data?.id; + + if (!userName || !id) { + setStatusText("缺少组件 ID 或用户信息"); + return; + } + if (!userName) { setStatusText("未登录,跳转中..."); window.location.href = "/auth/sign-in/"; @@ -401,7 +408,7 @@ export function DetailPageHeader({ data }: { data: any }) { const res = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ user_name: userName, id: data.id }), + body: JSON.stringify({ user_name: userName, id: id }), }); const json = await res.json();