Skip to content

Commit 314d089

Browse files
committed
fix(app-check)!: options is required in initializeAppCheck matching firebase-js-sdk
Require AppCheckOptions at the modular entry point and reject missing options before native initialization. Document the stricter parameter in compare-types; add runtime and type-test coverage.
1 parent 4380637 commit 314d089

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

.github/scripts/compare-types/configs/app-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const config: PackageConfig = {
8989
{
9090
name: 'initializeAppCheck',
9191
reason:
92-
'RN Firebase returns `Promise<AppCheck>` because App Check initialization crosses the native bridge, whereas the firebase-js-sdk returns `AppCheck` synchronously.',
92+
'RN Firebase returns `Promise<AppCheck>` because App Check initialization crosses the native bridge, whereas the firebase-js-sdk returns `AppCheck` synchronously. The `options` argument is required on RN Firebase because native initialization always needs a configured provider; the firebase-js-sdk declaration marks it optional even though a provider is required in practice.',
9393
},
9494
{
9595
name: 'AppCheckOptions',

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', async function () {
24+
await expect(initializeAppCheck(undefined, undefined as any)).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: 7 additions & 4 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,
@@ -255,11 +255,14 @@ function getModularAppCheck(app?: FirebaseApp): AppCheck {
255255
}
256256

257257
export async function initializeAppCheck(
258-
app?: FirebaseApp,
259-
options?: AppCheckOptions,
258+
app: FirebaseApp | undefined,
259+
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

packages/app-check/type-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ initializeAppCheck(getApp(), options).then((instance: AppCheck) => {
2525
console.log(instance.app.name);
2626
});
2727

28+
// @ts-expect-error options is required for App Check initialization
29+
initializeAppCheck(getApp());
30+
2831
getToken(appCheck).then((result: AppCheckTokenResult) => {
2932
console.log(result.token);
3033
});

0 commit comments

Comments
 (0)