From 385fa92802ca3254a4401ba47c2ebf6fba065962 Mon Sep 17 00:00:00 2001 From: longsizhuo Date: Tue, 14 Apr 2026 18:36:21 +0000 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20/api/user-cent?= =?UTF-8?q?er/*=20=E4=BB=A3=E7=90=86=20rewrite=20=E5=88=B0=E5=90=8E?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- next.config.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/next.config.mjs b/next.config.mjs index 8430484..1ea990d 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -40,6 +40,11 @@ const config = { source: "/analytics/:path*", destination: `${backendUrl}/analytics/:path*`, }, + { + // 用户中心 API(偏好设置等)代理到后端,避免浏览器跨域 + source: "/api/user-center/:path*", + destination: `${backendUrl}/api/user-center/:path*`, + }, ]; }, images: { From 30769653592934eb6265d1b9d4e1be31831eb1f1 Mon Sep 17 00:00:00 2001 From: longsizhuo Date: Tue, 14 Apr 2026 18:36:30 +0000 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20/settings=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E9=A1=B5=EF=BC=88Server=20Component=EF=BC=8C?= =?UTF-8?q?=E5=90=AB=20Newspaper=20=E9=A3=8E=E6=A0=BC=E5=B8=83=E5=B1=80?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/settings/page.tsx | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 app/settings/page.tsx diff --git a/app/settings/page.tsx b/app/settings/page.tsx new file mode 100644 index 0000000..978ed52 --- /dev/null +++ b/app/settings/page.tsx @@ -0,0 +1,53 @@ +// 用户偏好设置页(Server Component) +// 未登录时重定向到 /login?redirect=/settings +import { cookies } from "next/headers"; +import { Header } from "@/app/components/Header"; +import { Footer } from "@/app/components/Footer"; +import { SettingsForm } from "./SettingsForm"; + +async function getServerUser() { + const cookieStore = await cookies(); + const token = cookieStore.get("satoken")?.value; + if (!token || !process.env.BACKEND_URL) return null; + try { + const res = await fetch(`${process.env.BACKEND_URL}/auth/me`, { + headers: { satoken: token }, + cache: "no-store", + }); + if (!res.ok) return null; + const body = await res.json(); + return body?.data ?? null; + } catch { + return null; + } +} + +export default async function SettingsPage() { + const user = await getServerUser(); + + // satoken 存在于 localStorage 而非 cookie,服务端无法读取 + // 因此此处 user 可能为 null;实际登录态由客户端 SettingsForm 内部处理 + // 仅当能从服务端确认已登出时才重定向,避免误跳转 + // (大多数情况下 user 为 null 是正常的,由客户端 useAuth 判断) + void user; + + return ( + <> +
+
+
+
+

+ Settings +

+

+ User Preferences — Customize your experience +

+
+ +
+
+