Skip to content

Commit

Permalink
check that swizzling is enabled before patching
Browse files Browse the repository at this point in the history
  • Loading branch information
jey committed Dec 28, 2024
1 parent 266c27b commit d3f49a6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/auth/plugin/src/ios/openUrlFix.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import { ConfigPlugin, withAppDelegate, ExportedConfigWithProps } from '@expo/config-plugins';
import {
ConfigPlugin,
withAppDelegate,
withInfoPlist,
ExportedConfigWithProps,
} from '@expo/config-plugins';
import type { ExpoConfig } from '@expo/config/build/Config.types';
import type { AppDelegateProjectFile } from '@expo/config-plugins/build/ios/Paths';
import type { InfoPlist } from '@expo/config-plugins/build/ios/IosConfig.types';
import { mergeContents } from '@expo/config-plugins/build/utils/generateCode';
import { PluginConfigType } from '../pluginConfig';

export const withIosCaptchaOpenUrlFix: ConfigPlugin<PluginConfigType> = (
config: ExpoConfig,
props?: PluginConfigType,
) => {
// check configuration
if (!shouldApplyIosOpenUrlFix({ config, props })) {
return config;
}

// check that swizzling is enabled; otherwise patch must be customized and applied manually
withInfoPlist(config, config => {
if (isFirebaseSwizzlingDisabled(config)) {
throw new Error(
[
'Your app has disabled swizzling by setting FirebaseAppDelegateProxyEnabled=false in its Info.plist.',
"Please update your app.config.json to configure the '@react-native-firebase/auth' plugin to set `captchaOpenUrlFix: false`",
'and see https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling for instructions.',
].join(' '),
);
} else {
return config;
}
});

// apply patch
return withAppDelegate(config, config => {
return withOpenUrlFixForCaptcha({ config, props });
});
Expand Down Expand Up @@ -130,3 +153,7 @@ function isPluginEnabled(config: ExpoConfig, pluginName: string): boolean {
}
});
}

export function isFirebaseSwizzlingDisabled(config: ExportedConfigWithProps<InfoPlist>): boolean {
return config.ios?.infoPlist?.['FirebaseAppDelegateProxyEnabled'] === false;
}

0 comments on commit d3f49a6

Please sign in to comment.