This commit is contained in:
eric
2026-03-12 04:25:12 -05:00
parent 528044db7d
commit 39a8358af1
7 changed files with 190 additions and 12 deletions

View File

@@ -170,9 +170,9 @@ export default function Home() {
}, []);
const getOrCreateUserId = useCallback(async () => {
// 优先使用 PocketBase 用户 ID已登录时
// 优先使用 PocketBase 用户 ID已登录时,含跨站 Cookie
try {
const meRes = await fetch("/api/auth/me");
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
const meData = await meRes.json();
if (meData?.user?.id) {
const pbUserId = meData.user.id;
@@ -239,9 +239,10 @@ export default function Home() {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: result.token, record: result.record }),
credentials: "include",
});
const userId = result.record.id;
const vipRes = await fetch("/api/vip/check");
const vipRes = await fetch("/api/vip/check", { credentials: "include", cache: "no-store" });
const vipData = await vipRes.json();
if (vipData?.vip) {
setStorage("userId", userId);
@@ -307,7 +308,7 @@ export default function Home() {
const handlePay = useCallback(async () => {
try {
const meRes = await fetch("/api/auth/me");
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
const meData = await meRes.json();
if (meData?.user?.id) {
doPay();
@@ -368,16 +369,17 @@ export default function Home() {
return;
}
// SSO: 优先检查根域 Cookie跨站登录态
// SSO: 优先检查根域 Cookie跨站登录态,如从 digital 登录后跳转过来
try {
const meRes = await fetch("/api/auth/me");
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
const meData = await meRes.json();
if (meData?.user && meData?.token) {
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
pbSaveAuth(meData.token, { id: meData.user.id, email: meData.user.email });
const vipRes = await fetch("/api/vip/check");
const vipRes = await fetch("/api/vip/check", { credentials: "include", cache: "no-store" });
const vipData = await vipRes.json();
if (vipData?.vip) {
setStorage("userId", meData.user.id);
savePaidType("vip");
saveUserName(meData.user.email || meData.user.id);
setLoading(false);