From 71253b0c194ab6e09244d98d8a36d3d547e09f87 Mon Sep 17 00:00:00 2001 From: Thor Galle Date: Mon, 24 Jun 2024 18:58:37 +0300 Subject: [PATCH] feat: allow specifying an AppCheck debug token via localStorage --- src/lib/api/firebase.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/api/firebase.ts b/src/lib/api/firebase.ts index 3a2f4a98..65a516e4 100644 --- a/src/lib/api/firebase.ts +++ b/src/lib/api/firebase.ts @@ -124,9 +124,18 @@ export async function initialize(): Promise { } appRef = initializeApp(FIREBASE_CONFIG); + let appCheckDebugToken; if (typeof import.meta.env.VITE_FIREBASE_APPCHECK_DEBUG_TOKEN !== 'undefined') { - (self as any).FIREBASE_APPCHECK_DEBUG_TOKEN = - import.meta.env.VITE_FIREBASE_APPCHECK_DEBUG_TOKEN; + // Prioritize the static env debug token + appCheckDebugToken = import.meta.env.VITE_FIREBASE_APPCHECK_DEBUG_TOKEN; + } else if (browser && window) { + // But allow inserting a token via localStorage, for example for debugging in BrowserStack, + // which seems to be blocked by AppCheck. + appCheckDebugToken = window.localStorage.getItem('FIREBASE_APPCHECK_DEBUG_TOKEN'); + } + + if (appCheckDebugToken) { + (self as any).FIREBASE_APPCHECK_DEBUG_TOKEN = appCheckDebugToken; } if (typeof import.meta.env.VITE_FIREBASE_APP_CHECK_PUBLIC_KEY !== 'undefined') {