同步文件
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user