Skip to content

Commit f6cefe3

Browse files
committed
fix(app-check): guard missing initializeAppCheck options at runtime
Keep optional options matching firebase-js-sdk; reject undefined options with the same error as the macOS path before native initialization.
1 parent 314d089 commit f6cefe3

4 files changed

Lines changed: 5 additions & 8 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. 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.',
92+
'RN Firebase returns `Promise<AppCheck>` because App Check initialization crosses the native bridge, whereas the firebase-js-sdk returns `AppCheck` synchronously.',
9393
},
9494
{
9595
name: 'AppCheckOptions',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ 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(
23+
it('`initializeAppCheck` rejects missing options at runtime', async function () {
24+
await expect(initializeAppCheck(undefined, undefined)).rejects.toThrow(
2525
'Invalid configuration: no options defined.',
2626
);
2727
});

packages/app-check/lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ function getModularAppCheck(app?: FirebaseApp): AppCheck {
255255
}
256256

257257
export async function initializeAppCheck(
258-
app: FirebaseApp | undefined,
259-
options: AppCheckOptions,
258+
app?: FirebaseApp,
259+
options?: AppCheckOptions,
260260
): Promise<AppCheck> {
261261
if (!isObject(options)) {
262262
throw new Error('Invalid configuration: no options defined.');

packages/app-check/type-test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ 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-
3128
getToken(appCheck).then((result: AppCheckTokenResult) => {
3229
console.log(result.token);
3330
});

0 commit comments

Comments
 (0)