Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test": "jest",
"typecheck": "tsc",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
"prepare": "bob build && yarn build:plugin",
"build:plugin": "tsc --build plugin",
Expand Down
20 changes: 16 additions & 4 deletions plugin/src/withGoogleAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ const getAndroidClientIdFromJson = (
return null;
};

/**
* Helper function to convert iOS client ID to URL scheme
* Reverses the client ID to create the proper URL scheme
* e.g., "123456789.apps.googleusercontent.com" -> "com.googleusercontent.apps.123456789"
*/
const getUrlSchemeFromClientId = (clientId: string): string => {
return clientId.split('.').reverse().join('.');
};

/**
* Configure iOS for Google Sign-In
*/
Expand Down Expand Up @@ -176,9 +185,10 @@ const withGoogleAuthIOS: ConfigPlugin<Options> = (config, options) => {
iosConfig.modResults.GIDClientID = iosClientId;

// Add URL scheme
const urlScheme = options.iosUrlScheme || iosClientId.split('.')[0];
const urlScheme =
options.iosUrlScheme || getUrlSchemeFromClientId(iosClientId);
if (urlScheme) {
// Check if URL scheme already exists to prevent duplicates
// Check if the URL scheme already exists to prevent duplicates
if (!hasExistingUrlScheme(iosConfig.modResults, urlScheme)) {
iosConfig.modResults = appendScheme(urlScheme, iosConfig.modResults);
}
Expand Down Expand Up @@ -261,10 +271,12 @@ export const withGoogleUrlScheme: ConfigPlugin<Options> = (config, options) => {
return withInfoPlist(config, (iosConfig) => {
const urlScheme =
options.iosUrlScheme ||
(options.iosClientId ? options.iosClientId.split('.')[0] : null);
(options.iosClientId
? getUrlSchemeFromClientId(options.iosClientId)
: null);

if (urlScheme) {
// Check if URL scheme already exists to prevent duplicates
// Check if the URL scheme already exists to prevent duplicates
if (!hasExistingUrlScheme(iosConfig.modResults, urlScheme)) {
iosConfig.modResults = appendScheme(urlScheme, iosConfig.modResults);
}
Expand Down
Loading