From 7f0412e4a450696603bd1a2eac3957c21188c3c6 Mon Sep 17 00:00:00 2001 From: Jey Kottalam Date: Wed, 1 Jan 2025 21:08:22 -0800 Subject: [PATCH] print a warning when config is default and AppDelegate is modified --- .../__tests__/iosPlugin_openUrlFix.test.ts | 29 ++++++++++++++++++- packages/auth/plugin/src/ios/openUrlFix.ts | 9 +++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/auth/plugin/__tests__/iosPlugin_openUrlFix.test.ts b/packages/auth/plugin/__tests__/iosPlugin_openUrlFix.test.ts index 530fb366d7..fa2f16fa4c 100644 --- a/packages/auth/plugin/__tests__/iosPlugin_openUrlFix.test.ts +++ b/packages/auth/plugin/__tests__/iosPlugin_openUrlFix.test.ts @@ -199,6 +199,31 @@ describe('Config Plugin iOS Tests - openUrlFix', () => { const result = modifyObjcAppDelegate(appDelegate); expect(result).toMatchSnapshot(); }); + + it(`prints warning message when configured to default and AppDelegate is modified`, async () => { + const fixturePath = path.join(__dirname, 'fixtures', fixtureName); + const appDelegate = await fs.readFile(fixturePath, { encoding: 'utf-8' }); + const config = { + name: 'TestName', + slug: 'TestSlug', + modRequest: { projectRoot: path.join(__dirname, 'fixtures') } as any, + modResults: { + path: fixturePath, + language: 'objc', + contents: appDelegate, + } as AppDelegateProjectFile, + modRawConfig: { name: 'TestName', slug: 'TestSlug' }, + }; + const props = undefined; + const spy = jest + .spyOn(WarningAggregator, 'addWarningIOS') + .mockImplementation(() => undefined); + withOpenUrlFixForAppDelegate({ config, props }); + expect(spy).toHaveBeenCalledWith( + '@react-native-firebase/auth', + 'modifying iOS AppDelegate openURL method to ignore firebaseauth reCAPTCHA redirect URLs', + ); + }); }); const appDelegateFixturesNoop = ['AppDelegate_sdk42.m', 'AppDelegate_fallback.m']; @@ -219,7 +244,9 @@ describe('Config Plugin iOS Tests - openUrlFix', () => { modRawConfig: { name: 'TestName', slug: 'TestSlug' }, }; const props = undefined; - const spy = jest.spyOn(WarningAggregator, 'addWarningIOS'); + const spy = jest + .spyOn(WarningAggregator, 'addWarningIOS') + .mockImplementation(() => undefined); const result = withOpenUrlFixForAppDelegate({ config, props }); expect(result.modResults.contents).toBe(appDelegate); expect(spy).toHaveBeenCalledWith( diff --git a/packages/auth/plugin/src/ios/openUrlFix.ts b/packages/auth/plugin/src/ios/openUrlFix.ts index 0e0b5adfe8..eb05f21edf 100644 --- a/packages/auth/plugin/src/ios/openUrlFix.ts +++ b/packages/auth/plugin/src/ios/openUrlFix.ts @@ -60,11 +60,12 @@ export function withOpenUrlFixForAppDelegate({ props?: PluginConfigType; }) { const { language, contents } = config.modResults; + const configValue = props?.ios?.captchaOpenUrlFix || 'default'; if (['objc', 'objcpp'].includes(language)) { const newContents = modifyObjcAppDelegate(contents); if (newContents === null) { - if (props?.ios?.captchaOpenUrlFix === true) { + if (configValue === true) { throw new Error("Failed to apply iOS openURL fix because no 'openURL' method was found"); } else { WarningAggregator.addWarningIOS( @@ -74,6 +75,12 @@ export function withOpenUrlFixForAppDelegate({ return config; } } else { + if (configValue === 'default') { + WarningAggregator.addWarningIOS( + '@react-native-firebase/auth', + 'modifying iOS AppDelegate openURL method to ignore firebaseauth reCAPTCHA redirect URLs', + ); + } return { ...config, modResults: {