Skip to content

Commit b1e4590

Browse files
feat: Enhance addAuth0AppDelegateCode to accept language parameter for Swift detection
1 parent f4447b6 commit b1e4590

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/plugin/withAuth0.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,21 @@ const withAndroidAuth0Manifest: ConfigPlugin<Auth0PluginConfig[]> = (
106106
});
107107
};
108108

109-
export const addAuth0AppDelegateCode = (src: string): string => {
109+
export const addAuth0AppDelegateCode = (
110+
src: string,
111+
language: string
112+
): string => {
110113
let tempSrc = src;
111114

112115
// Check if this is a Swift app delegate file by looking for Swift syntax patterns
113116
// rather than relying on import statements that may change
114-
const isSwift =
115-
src.includes('class AppDelegate: ExpoAppDelegate') ||
116-
(src.includes('@UIApplicationMain') && src.includes('class AppDelegate'));
117+
const isSwift = language === 'swift';
117118

118119
if (!isSwift) {
119-
// For non-Swift files, return unchanged since we're only supporting Swift app delegates
120-
return tempSrc;
120+
// Throw error for non-Swift files, since we're only supporting Swift app delegates (RN 78+)
121+
throw new Error(
122+
'This plugin only supports expo 53 or greater. If you are using older version 4.x'
123+
);
121124
}
122125

123126
// Swift handling for Expo 53+
@@ -146,7 +149,8 @@ export const addAuth0AppDelegateCode = (src: string): string => {
146149
const withIOSAuth0AppDelegate: ConfigPlugin<Auth0PluginConfig[]> = (config) => {
147150
return withAppDelegate(config, (config) => {
148151
const src = config.modResults.contents;
149-
config.modResults.contents = addAuth0AppDelegateCode(src);
152+
const language = config.modResults.language;
153+
config.modResults.contents = addAuth0AppDelegateCode(src, language);
150154
return config;
151155
});
152156
};

0 commit comments

Comments
 (0)