From 74d324ee1977ab3c9fe6ab2c90921349aac33f80 Mon Sep 17 00:00:00 2001 From: Ahmed Sbai Date: Tue, 13 Jan 2026 22:40:26 +0100 Subject: [PATCH] refactor(google-auth): introduce helper for iOS client ID URL scheme conversion - Added `getUrlSchemeFromClientId` to simplify and standardize URL scheme creation. - Updated iOS configuration logic to use the new helper function. - Included a new `lint:fix` script in package.json for automated linting fixes. --- package.json | 1 + plugin/src/withGoogleAuth.ts | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 267e98b..7cce377 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin/src/withGoogleAuth.ts b/plugin/src/withGoogleAuth.ts index 66fafd1..b232da5 100644 --- a/plugin/src/withGoogleAuth.ts +++ b/plugin/src/withGoogleAuth.ts @@ -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 */ @@ -176,9 +185,10 @@ const withGoogleAuthIOS: ConfigPlugin = (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); } @@ -261,10 +271,12 @@ export const withGoogleUrlScheme: ConfigPlugin = (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); }