Skip to content

Commit

Permalink
print a warning when config is default and AppDelegate is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
jey committed Jan 2, 2025
1 parent 11a36ab commit 7f0412e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 28 additions & 1 deletion packages/auth/plugin/__tests__/iosPlugin_openUrlFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion packages/auth/plugin/src/ios/openUrlFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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: {
Expand Down

0 comments on commit 7f0412e

Please sign in to comment.