@@ -6,22 +6,43 @@ import {
6
6
} from 'firebase/app-check'
7
7
import { App , inject , InjectionKey , Ref , ref } from 'vue'
8
8
import { getGlobalScope } from '../globals'
9
+ import { isClient } from '../shared'
9
10
10
11
export const AppCheckTokenInjectSymbol : InjectionKey < Ref < string | undefined > > =
11
12
Symbol ( 'app-check-token' )
12
13
14
+ /**
15
+ * The current app-check token as a `Ref`. Note this is undefined on the server.
16
+ */
13
17
export function useAppCheckToken ( ) {
14
18
return inject ( AppCheckTokenInjectSymbol ) !
15
19
}
16
20
17
- export function VueFireAppCheck ( options : AppCheckOptions ) {
21
+ export interface VueFireAppCheckOptions extends AppCheckOptions {
22
+ /**
23
+ * Setups the debug token global. See https://firebase.google.com/docs/app-check/web/debug-provider. Note you should
24
+ * set to false in production (or not set it at all).
25
+ */
26
+ debug ?: boolean
27
+ }
28
+
29
+ export function VueFireAppCheck ( options : VueFireAppCheckOptions ) {
18
30
return ( firebaseApp : FirebaseApp , app : App ) => {
19
- const appCheck = initializeAppCheck ( firebaseApp , options )
31
+ // provide this even on the server for simplicity of usage
20
32
const token = getGlobalScope ( firebaseApp , app ) . run ( ( ) => ref < string > ( ) ) !
33
+ app . provide ( AppCheckTokenInjectSymbol , token )
34
+
35
+ // AppCheck is client only as it relies on browser apis
36
+ if ( ! isClient ) return
37
+
38
+ if ( options . debug ) {
39
+ // @ts -expect-error: local override
40
+ self . FIREBASE_APPCHECK_DEBUG_TOKEN = true
41
+ }
42
+
43
+ const appCheck = initializeAppCheck ( firebaseApp , options )
21
44
onTokenChanged ( appCheck , ( newToken ) => {
22
45
token . value = newToken . token
23
46
} )
24
-
25
- app . provide ( AppCheckTokenInjectSymbol , token )
26
47
}
27
48
}
0 commit comments