From b36c712ee43d5bfbd487ee3e954ec101209f5d8d Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Wed, 20 May 2026 21:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/account/__tests__/paymentShell.test.ts | 1 + .../ops/subscriptions/SubscriptionsPageClient.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/components/account/__tests__/paymentShell.test.ts b/frontend/components/account/__tests__/paymentShell.test.ts index 980ccd30..d5c5d6f3 100644 --- a/frontend/components/account/__tests__/paymentShell.test.ts +++ b/frontend/components/account/__tests__/paymentShell.test.ts @@ -78,6 +78,7 @@ export function runTests() { ); assert( subscriptionsPageSource.includes("getSupabaseBrowserClient") && + subscriptionsPageSource.includes("refreshSession") && subscriptionsPageSource.includes("Authorization") && subscriptionsPageSource.includes("/api/ops/subscriptions/grant") && subscriptionsPageSource.includes("/api/ops/subscriptions/extend"), diff --git a/frontend/components/ops/subscriptions/SubscriptionsPageClient.tsx b/frontend/components/ops/subscriptions/SubscriptionsPageClient.tsx index 78dad82b..cf918c1d 100644 --- a/frontend/components/ops/subscriptions/SubscriptionsPageClient.tsx +++ b/frontend/components/ops/subscriptions/SubscriptionsPageClient.tsx @@ -15,9 +15,15 @@ async function buildOpsAuthHeaders() { }; if (!hasSupabasePublicEnv()) return headers; try { - const { + const supabase = getSupabaseBrowserClient(); + let { data: { session }, - } = await getSupabaseBrowserClient().auth.getSession(); + } = await supabase.auth.getSession(); + const expiresAtMs = Number(session?.expires_at || 0) * 1000; + if (session && expiresAtMs > 0 && expiresAtMs - Date.now() < 60_000) { + const refreshed = await supabase.auth.refreshSession(); + session = refreshed.data.session || session; + } const token = String(session?.access_token || "").trim(); if (token) headers.Authorization = `Bearer ${token}`; } catch {