File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ export interface FirebaseAppCheckInternal {
28
28
29
29
// Unregisters a listener to changes in the token state.
30
30
removeTokenListener ( listener : AppCheckTokenListener ) : void ;
31
+
32
+ // Returns true if user has initialized App Check.
33
+ isInitialized ( ) : boolean ;
31
34
}
32
35
33
36
type AppCheckTokenListener = ( token : AppCheckTokenResult ) => void ;
Original file line number Diff line number Diff line change @@ -26,7 +26,10 @@ import {
26
26
} from './internal-api' ;
27
27
import { Provider } from '@firebase/component' ;
28
28
29
+ const isInitializedMap : Record < string , boolean > = { } ;
30
+
29
31
export function factory ( app : FirebaseApp ) : FirebaseAppCheck {
32
+ isInitializedMap [ app . options . appId ! ] = true ;
30
33
return {
31
34
activate : (
32
35
siteKeyOrProvider : string | AppCheckProvider ,
@@ -42,6 +45,7 @@ export function internalFactory(
42
45
platformLoggerProvider : Provider < 'platform-logger' >
43
46
) : FirebaseAppCheckInternal {
44
47
return {
48
+ isInitialized : ( ) => isInitializedMap [ app . options . appId ! ] ,
45
49
getToken : forceRefresh =>
46
50
getToken ( app , platformLoggerProvider , forceRefresh ) ,
47
51
addTokenListener : listener =>
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ export class StorageService implements _FirebaseService {
254
254
255
255
async _getAppCheckToken ( ) : Promise < string | null > {
256
256
const appCheck = this . _appCheckProvider . getImmediate ( { optional : true } ) ;
257
- if ( appCheck ) {
257
+ if ( appCheck && appCheck . isInitialized ( ) ) {
258
258
const result = await appCheck . getToken ( ) ;
259
259
// TODO: What do we want to do if there is an error getting the token?
260
260
// Context: appCheck.getToken() will never throw even if an error happened. In the error case, a dummy token will be
You can’t perform that action at this time.
0 commit comments