From ec87813a257e63f8a161e7bc04679e9fab6fbcf6 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 9 Nov 2025 12:21:54 +0000 Subject: feat(extension): Add custom header support for extension (#2111) Fixes #1287 --- apps/browser-extension/src/utils/trpc.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'apps/browser-extension/src/utils/trpc.ts') diff --git a/apps/browser-extension/src/utils/trpc.ts b/apps/browser-extension/src/utils/trpc.ts index 76534bcb..b3215d9d 100644 --- a/apps/browser-extension/src/utils/trpc.ts +++ b/apps/browser-extension/src/utils/trpc.ts @@ -18,10 +18,11 @@ let currentSettings: { apiKey: string; badgeCacheExpireMs: number; useBadgeCache: boolean; + customHeaders: Record; } | null = null; export async function initializeClients() { - const { address, apiKey, badgeCacheExpireMs, useBadgeCache } = + const { address, apiKey, badgeCacheExpireMs, useBadgeCache, customHeaders } = await getPluginSettings(); if (currentSettings) { @@ -31,6 +32,9 @@ export async function initializeClients() { currentSettings.badgeCacheExpireMs !== badgeCacheExpireMs; const useBadgeCacheChanged = currentSettings.useBadgeCache !== useBadgeCache; + const customHeadersChanged = + JSON.stringify(currentSettings.customHeaders) !== + JSON.stringify(customHeaders); if (!address || !apiKey) { // Invalid configuration, clean @@ -40,7 +44,7 @@ export async function initializeClients() { return; } - if (addressChanged || apiKeyChanged) { + if (addressChanged || apiKeyChanged || customHeadersChanged) { // Switch context completely → discard the old instance and wipe persisted cache const persisterForCleanup = createChromeStorage(); await persisterForCleanup.removeClient(); @@ -58,7 +62,8 @@ export async function initializeClients() { !addressChanged && !apiKeyChanged && !cacheTimeChanged && - !useBadgeCacheChanged + !useBadgeCacheChanged && + !customHeadersChanged ) { return; } @@ -66,7 +71,13 @@ export async function initializeClients() { if (address && apiKey) { // Store current settings - currentSettings = { address, apiKey, badgeCacheExpireMs, useBadgeCache }; + currentSettings = { + address, + apiKey, + badgeCacheExpireMs, + useBadgeCache, + customHeaders, + }; // Create new QueryClient with updated settings queryClient = new QueryClient(); @@ -92,6 +103,7 @@ export async function initializeClients() { headers() { return { Authorization: `Bearer ${apiKey}`, + ...customHeaders, }; }, transformer: superjson, -- cgit v1.2.3-70-g09d2