@@ -6,22 +6,43 @@ import {
66} from 'firebase/app-check'
77import { App , inject , InjectionKey , Ref , ref } from 'vue'
88import { getGlobalScope } from '../globals'
9+ import { isClient } from '../shared'
910
1011export const AppCheckTokenInjectSymbol : InjectionKey < Ref < string | undefined > > =
1112 Symbol ( 'app-check-token' )
1213
14+ /**
15+ * The current app-check token as a `Ref`. Note this is undefined on the server.
16+ */
1317export function useAppCheckToken ( ) {
1418 return inject ( AppCheckTokenInjectSymbol ) !
1519}
1620
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 ) {
1830 return ( firebaseApp : FirebaseApp , app : App ) => {
19- const appCheck = initializeAppCheck ( firebaseApp , options )
31+ // provide this even on the server for simplicity of usage
2032 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 )
2144 onTokenChanged ( appCheck , ( newToken ) => {
2245 token . value = newToken . token
2346 } )
24-
25- app . provide ( AppCheckTokenInjectSymbol , token )
2647 }
2748}
0 commit comments