17
17
18
18
import { getDebugState } from './state' ;
19
19
import { readOrCreateDebugTokenFromStorage } from './storage' ;
20
- import { Deferred } from '@firebase/util' ;
20
+ import { Deferred , getGlobal } from '@firebase/util' ;
21
21
22
22
declare global {
23
- interface Window {
24
- /**
25
- * When it is a string, we treat it as the debug token and give it to consumers as the app check token
26
- * When it is `true`, we will try to read the debug token from the indexeddb,
27
- * if it doesn't exist, create one, print it to console, and ask developers to register it in the Firebase console.
28
- * When it is `undefined`, `false` or any unsupported value type, the SDK will operate in production mode
29
- */
30
- FIREBASE_APPCHECK_DEBUG_TOKEN ?: boolean | string ;
31
- }
23
+ // var must be used for global scopes
24
+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis
25
+ // eslint-disable-next-line no-var
26
+ var FIREBASE_APPCHECK_DEBUG_TOKEN : boolean | string | undefined ;
32
27
}
33
28
34
29
export function isDebugMode ( ) : boolean {
@@ -50,9 +45,10 @@ export async function getDebugToken(): Promise<string> {
50
45
}
51
46
52
47
export function initializeDebugMode ( ) : void {
48
+ const globals = getGlobal ( ) ;
53
49
if (
54
- typeof self . FIREBASE_APPCHECK_DEBUG_TOKEN !== 'string' &&
55
- self . FIREBASE_APPCHECK_DEBUG_TOKEN !== true
50
+ typeof globals . FIREBASE_APPCHECK_DEBUG_TOKEN !== 'string' &&
51
+ globals . FIREBASE_APPCHECK_DEBUG_TOKEN !== true
56
52
) {
57
53
return ;
58
54
}
@@ -62,8 +58,8 @@ export function initializeDebugMode(): void {
62
58
const deferredToken = new Deferred < string > ( ) ;
63
59
debugState . token = deferredToken ;
64
60
65
- if ( typeof self . FIREBASE_APPCHECK_DEBUG_TOKEN === 'string' ) {
66
- deferredToken . resolve ( self . FIREBASE_APPCHECK_DEBUG_TOKEN ) ;
61
+ if ( typeof globals . FIREBASE_APPCHECK_DEBUG_TOKEN === 'string' ) {
62
+ deferredToken . resolve ( globals . FIREBASE_APPCHECK_DEBUG_TOKEN ) ;
67
63
} else {
68
64
deferredToken . resolve ( readOrCreateDebugTokenFromStorage ( ) ) ;
69
65
}
0 commit comments