同步文件

This commit is contained in:
2569718930@qq.com
2026-05-20 21:18:59 +08:00
parent a0005b1e37
commit b36c712ee4
2 changed files with 9 additions and 2 deletions
@@ -78,6 +78,7 @@ export function runTests() {
); );
assert( assert(
subscriptionsPageSource.includes("getSupabaseBrowserClient") && subscriptionsPageSource.includes("getSupabaseBrowserClient") &&
subscriptionsPageSource.includes("refreshSession") &&
subscriptionsPageSource.includes("Authorization") && subscriptionsPageSource.includes("Authorization") &&
subscriptionsPageSource.includes("/api/ops/subscriptions/grant") && subscriptionsPageSource.includes("/api/ops/subscriptions/grant") &&
subscriptionsPageSource.includes("/api/ops/subscriptions/extend"), subscriptionsPageSource.includes("/api/ops/subscriptions/extend"),
@@ -15,9 +15,15 @@ async function buildOpsAuthHeaders() {
}; };
if (!hasSupabasePublicEnv()) return headers; if (!hasSupabasePublicEnv()) return headers;
try { try {
const { const supabase = getSupabaseBrowserClient();
let {
data: { session }, 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(); const token = String(session?.access_token || "").trim();
if (token) headers.Authorization = `Bearer ${token}`; if (token) headers.Authorization = `Bearer ${token}`;
} catch { } catch {