Skip to content

Commit ceeb13e

Browse files
committed
Check app check init
1 parent 8bece48 commit ceeb13e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

packages/app-check-interop-types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface FirebaseAppCheckInternal {
2828

2929
// Unregisters a listener to changes in the token state.
3030
removeTokenListener(listener: AppCheckTokenListener): void;
31+
32+
// Returns true if user has initialized App Check.
33+
isInitialized(): boolean;
3134
}
3235

3336
type AppCheckTokenListener = (token: AppCheckTokenResult) => void;

packages/app-check/src/factory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {
2626
} from './internal-api';
2727
import { Provider } from '@firebase/component';
2828

29+
const isInitializedMap: Record<string, boolean> = {};
30+
2931
export function factory(app: FirebaseApp): FirebaseAppCheck {
32+
isInitializedMap[app.options.appId!] = true;
3033
return {
3134
activate: (
3235
siteKeyOrProvider: string | AppCheckProvider,
@@ -42,6 +45,7 @@ export function internalFactory(
4245
platformLoggerProvider: Provider<'platform-logger'>
4346
): FirebaseAppCheckInternal {
4447
return {
48+
isInitialized: () => isInitializedMap[app.options.appId!],
4549
getToken: forceRefresh =>
4650
getToken(app, platformLoggerProvider, forceRefresh),
4751
addTokenListener: listener =>

packages/storage/src/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class StorageService implements _FirebaseService {
254254

255255
async _getAppCheckToken(): Promise<string | null> {
256256
const appCheck = this._appCheckProvider.getImmediate({ optional: true });
257-
if (appCheck) {
257+
if (appCheck && appCheck.isInitialized()) {
258258
const result = await appCheck.getToken();
259259
// TODO: What do we want to do if there is an error getting the token?
260260
// Context: appCheck.getToken() will never throw even if an error happened. In the error case, a dummy token will be

0 commit comments

Comments
 (0)