Skip to content

Commit 1410831

Browse files
committed
fix(app-check): guard missing initializeAppCheck options at runtime
reject undefined options with same error as other path before native initialization.
1 parent 4380637 commit 1410831

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/app-check/__tests__/appcheck.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('appCheck()', function () {
2020
expect(initializeAppCheck).toBeDefined();
2121
});
2222

23+
it('`initializeAppCheck` rejects missing options at runtime', async function () {
24+
await expect(initializeAppCheck(undefined, undefined)).rejects.toThrow(
25+
'Invalid configuration: no options defined.',
26+
);
27+
});
28+
2329
it('`getToken` function is properly exposed to end user', function () {
2430
expect(getToken).toBeDefined();
2531
});

packages/app-check/lib/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import {
1919
isBoolean,
2020
isIOS,
21-
isString,
2221
isObject,
22+
isString,
2323
isUndefined,
2424
isOther,
2525
parseListenerOrObserver,
@@ -258,8 +258,11 @@ export async function initializeAppCheck(
258258
app?: FirebaseApp,
259259
options?: AppCheckOptions,
260260
): Promise<AppCheck> {
261+
if (!isObject(options)) {
262+
throw new Error('Invalid configuration: no options defined.');
263+
}
261264
const appCheck = getModularAppCheck(app);
262-
await (appCheck as AppCheckInternal).initializeAppCheck(options as AppCheckOptions);
265+
await (appCheck as AppCheckInternal).initializeAppCheck(options);
263266
return appCheck;
264267
}
265268

0 commit comments

Comments
 (0)