Skip to content

Commit

Permalink
feat: allow specifying an AppCheck debug token via localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rgall committed Jun 24, 2024
1 parent 30e1be7 commit 71253b0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/api/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,18 @@ export async function initialize(): Promise<void> {
}
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') {
Expand Down

0 comments on commit 71253b0

Please sign in to comment.