### Start Example App Packager Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Starts the Metro server for the example application. Changes to JavaScript code in the library will be reflected without a rebuild. ```sh yarn example start ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Builds and runs the example application on an iOS simulator or device. ```sh yarn example ios ``` -------------------------------- ### Install React Native Google Sign-In Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Install the library using npm or yarn. ```bash npm install @novastera-oss/rn-google-signin # or yarn add @novastera-oss/rn-google-signin ``` -------------------------------- ### Run Example App on Android Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Run this command in the root directory to install all project dependencies using Yarn workspaces. ```sh yarn ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/darksorrow/rn-google-signin/blob/main/example/README.md Run this command from the root of your React Native project to start the Metro dev server. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install @novastera-oss/rn-google-signin Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Install the package using npm or yarn. Ensure React Native New Architecture is enabled. ```bash npm install @novastera-oss/rn-google-signin # or yarn add @novastera-oss/rn-google-signin ``` ```bash # iOS — enable New Architecture cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install # Android — add to android/gradle.properties newArchEnabled=true ``` -------------------------------- ### Install Expo Plugin (SDK 48 and below) Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Use these commands to install the Google Sign-In Expo plugin for Expo SDK 48 and older. ```bash npm install @novastera-oss/rn-google-signin ``` ```bash yarn add @novastera-oss/rn-google-signin ``` -------------------------------- ### Configure and Use Google Sign-In Module in Swift Source: https://github.com/darksorrow/rn-google-signin/blob/main/ios/README.md Configure the module with client IDs and scopes, then use it for sign-in, checking status, getting user info, and signing out. Ensure all async operations are awaited. ```swift RnGoogleSignin.configure([ "iosClientId": "your-ios-client-id", "webClientId": "your-web-client-id", "scopes": ["profile", "email"] ]) // Sign in let result = await RnGoogleSignin.signIn(null) // Check sign-in status let isSignedIn = await RnGoogleSignin.isSignedIn() // Get current user let user = await RnGoogleSignin.getCurrentUser() // Sign out await RnGoogleSignin.signOut() ``` -------------------------------- ### Install Expo Plugin (SDK 49+) Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Use this command to install the Google Sign-In Expo plugin for Expo SDK 49 and newer. ```bash npx expo install @novastera-oss/rn-google-signin ``` -------------------------------- ### Complete Manual iOS Configuration for Expo Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Provides a comprehensive manual configuration example for iOS within an Expo project's app.json. This includes bundle identifiers, URL schemes, GIDClientID, and background modes. Remember to replace placeholders with your actual values. ```json { "expo": { "ios": { "bundleIdentifier": "com.yourcompany.yourapp", "supportsTablet": true, "infoPlist": { "CFBundleURLTypes": [ { "CFBundleURLSchemes": [ "com.googleusercontent.apps.your-ios-client-id" ] }, { "CFBundleURLSchemes": [ "com.yourcompany.yourapp" ] } ], "GIDClientID": "your-ios-client-id.apps.googleusercontent.com", "UIBackgroundModes": ["fetch", "remote-notification"] }, "entitlements": { "aps-environment": "development" } } } } ``` -------------------------------- ### Install CocoaPods Dependencies for iOS Source: https://github.com/darksorrow/rn-google-signin/blob/main/example/README.md Before running the iOS app, install CocoaPods dependencies. Run 'bundle install' once to install CocoaPods itself, then 'bundle exec pod install' after updating native dependencies. ```sh bundle install bundle exec pod install ``` -------------------------------- ### Build and Run iOS App Source: https://github.com/darksorrow/rn-google-signin/blob/main/example/README.md After installing CocoaPods dependencies, use these commands to build and run the iOS application. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Discord Server Rules Example Source: https://github.com/darksorrow/rn-google-signin/blob/main/DISCORD_SETUP.md This is a comprehensive set of server rules for a community focused on development and productivity tools. It covers respect, topic relevance, spam, content guidelines, server integrity, professional conduct, technology discussions, and moderation. ```markdown 📋 **NOVASTERA DISCORD SERVER RULES** Welcome to the Novastera community! This server is dedicated to discussing the development of Novastera and our technologies. We build productivity tools for different companies. 1. **Be Respectful** - Treat all members with respect and kindness - No harassment, hate speech, or discrimination - Constructive criticism is welcome, personal attacks are not 2. **Stay On Topic** - Use appropriate channels for discussions - Focus discussions on Novastera technologies, productivity tools, and development - Keep off-topic conversations in #off-topic - Read channel descriptions before posting 3. **No Spam** - No excessive messaging, emoji spam, or self-promotion - Follow slow mode limits in channels - No advertising without permission 4. **Content Guidelines** - No NSFW content - No pirated software or illegal content - Respect intellectual property - Keep discussions professional when discussing company clients 5. **Server Integrity** - No attempts to hack, exploit, or disrupt the server - No sharing of malicious links - Report bugs to admins, don't exploit them 6. **Professional Conduct** - Maintain professionalism in work-related channels - Use appropriate language for a professional environment - Respect confidentiality of company information and client data - When discussing productivity tools for companies, maintain professional discretion 7. **Technology Discussions** - Share knowledge about productivity tools and technologies - Help others understand Novastera's development - Discuss use cases and implementations respectfully 8. **Moderation** - Staff decisions are final - Appeals can be discussed privately with admins - Repeated rule violations may result in bans **Violations of these rules may result in warnings, mutes, or bans.** ``` -------------------------------- ### `signIn(options: SignInParams): Promise` Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Presents the Google account picker UI to the user and returns a `SignInResponse` containing the user profile, granted scopes, and tokens. On Android a cryptographically random nonce is auto-generated unless one is explicitly supplied. The method rejects any concurrent pending sign-in before starting a new one. ```APIDOC ## `signIn(options: SignInParams): Promise` ### Description Presents the Google account picker UI to the user and returns a `SignInResponse` containing the user profile, granted scopes, and tokens. On Android a cryptographically random nonce is auto-generated unless one is explicitly supplied. The method rejects any concurrent pending sign-in before starting a new one. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **nonce** (string) - Optional - A cryptographically random nonce. Auto-generated if omitted on Android. - **scopes** (string[]) - Optional - An array of scopes to request. iOS only. ### Request Example ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; async function handleSignIn() { try { const result = await RnGoogleSignin.signIn({ // nonce: 'custom-nonce-value', // scopes: ['https://www.googleapis.com/auth/calendar'], // iOS only }); console.log('User ID: ', result.user.id); console.log('Name: ', result.user.name); console.log('Email: ', result.user.email); console.log('Photo: ', result.user.photo); console.log('ID Token: ', result.idToken?.substring(0, 30) + '...'); console.log('Scopes: ', result.scopes); } catch (error: any) { console.error('Sign-in error:', error.message); } } ``` ### Response #### Success Response (200) - **user** (object) - User profile information. - **id** (string) - User's unique identifier. - **name** (string) - User's full name. - **email** (string) - User's email address. - **photo** (string) - URL to the user's profile picture. - **familyName** (string) - User's last name. - **givenName** (string) - User's first name. - **scopes** (string[]) - Array of granted OAuth scopes. - **idToken** (string) - The ID token for authentication. - **serverAuthCode** (string | null) - Server authorization code (if requested). #### Response Example ```json { "user": { "id": "1234567890", "name": "Jane Doe", "email": "jane@example.com", "photo": "https://lh3.googleusercontent.com/a/photo", "familyName": "Doe", "givenName": "Jane" }, "scopes": ["profile", "email", "openid"], "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6...", "serverAuthCode": null } ``` ### Error Handling - **sign_in_cancelled**: User cancelled the sign-in flow. - **no_credential**: No Google account found on the device or app not registered. - **not_configured**: `configure()` must be called before `signIn()`. - **network_error**: Network is unavailable. - **play_services_not_available**: Google Play Services is missing. ``` -------------------------------- ### Get Android App SHA-1 (Debug Build) Source: https://github.com/darksorrow/rn-google-signin/blob/main/example/README.md Obtain the SHA-1 fingerprint for your debug build by navigating to the 'android' directory and running the gradlew signingReport command, or by using the keytool command. ```sh cd android && ./gradlew signingReport ``` ```sh keytool -list -v -keystore app/debug.keystore -alias androiddebugkey -storepass android -keypass android ``` -------------------------------- ### Get Google Authentication Tokens Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Returns the current idToken and accessToken for the signed-in user. Note that on Android, accessToken and idToken are the same due to Credential Manager limitations. Use this to authenticate with Google APIs. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; import type { GetTokensResponse } from '@novastera-oss/rn-google-signin'; async function refreshAndUseTokens() { try { const tokens: GetTokensResponse = await RnGoogleSignin.getTokens(); console.log('ID Token (first 30):', tokens.idToken?.substring(0, 30)); console.log('Access Token (first 30):', tokens.accessToken?.substring(0, 30)); // Note: on Android accessToken === idToken (Credential Manager limitation) // Use the access token to call a Google API (iOS only has a distinct access token) const response = await fetch('https://www.googleapis.com/oauth2/v1/userinfo', { headers: { Authorization: `Bearer ${tokens.accessToken}` }, }); const profile = await response.json(); console.log('Google profile:', profile); } catch (error: any) { if (error.code === 'sign_in_required') { console.log('No user signed in — call signIn() first'); } else { console.error('getTokens failed:', error.message); } } } ``` -------------------------------- ### Get Current Google User Information Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Retrieves the currently signed-in User object or null if no user is authenticated. This function is essential for accessing user profile details after sign-in. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; import type { User } from '@novastera-oss/rn-google-signin'; async function loadCurrentUser(): Promise { try { const user = await RnGoogleSignin.getCurrentUser(); if (user) { console.log(`Hello, ${user.givenName ?? user.name}!`); console.log('Email:', user.email); console.log('Photo:', user.photo); } else { console.log('No user signed in'); } return user; } catch (error: any) { console.error('getCurrentUser failed:', error.message); return null; } } ``` -------------------------------- ### Testing the Plugin Locally Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Commands to build the module and link it in your Expo project for local testing. This involves building the module and then running `npx expo prebuild`. ```bash yarn prepare ``` ```bash npx expo prebuild ``` -------------------------------- ### configure Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Configures the library with Google client IDs. It supports both manual configuration with explicit client IDs and automatic detection from configuration files. ```APIDOC ## configure ### Description Configures the library with Google client IDs. It supports both manual configuration with explicit client IDs and automatic detection from configuration files. ### Method `RnGoogleSignin.configure(options)` ### Parameters #### Request Body - **options** (object) - Required - Configuration options. - **webClientId** (string) - Optional - Your Google web client ID. - **androidClientId** (string) - Optional - Your Google Android client ID (alias for webClientId). - **iosClientId** (string) - Optional - Your Google iOS client ID. ### Request Example ```typescript RnGoogleSignin.configure({ webClientId: 'your-web-client-id.apps.googleusercontent.com', androidClientId: 'your-android-client-id.apps.googleusercontent.com', iosClientId: 'your-ios-client-id.apps.googleusercontent.com', }); // For automatic detection (fallback) RnGoogleSignin.configure({}); ``` ``` -------------------------------- ### signIn Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Initiates the Google Sign-In flow for the user. Requires an empty object as a parameter due to TurboModule requirements. ```APIDOC ## signIn ### Description Initiates the Google Sign-In flow for the user. Requires an empty object as a parameter due to TurboModule requirements. ### Method `RnGoogleSignin.signIn(params)` ### Parameters #### Request Body - **params** (object) - Required - Must be an empty object `{}`. ### Request Example ```typescript try { const userInfo = await RnGoogleSignin.signIn({}); console.log('User info:', userInfo); } catch (error) { console.error('Sign in error:', error); } ``` ### Response #### Success Response (200) - **userInfo** (object) - Contains user information upon successful sign-in. - **idToken** (string) - The user's ID token. - **email** (string) - The user's email address. - **name** (string) - The user's full name. - **givenName** (string) - The user's given name. - **familyName** (string) - The user's family name. - **photoURL** (string) - The URL to the user's profile picture. - **scopes** (array) - An array of granted scopes. - **serverAuthCode** (string) - The server authorization code (if requested). - **hostedDomain** (string) - The user's hosted domain (if applicable). ### Response Example ```json { "idToken": "...", "email": "user@example.com", "name": "John Doe", "givenName": "John", "familyName": "Doe", "photoURL": "https://...", "scopes": ["email", "profile"], "serverAuthCode": "...", "hostedDomain": "example.com" } ``` ``` -------------------------------- ### configure Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Synchronously configures the Google Sign-In module with client IDs and optional settings. This method must be called before any other method in the library. ```APIDOC ## configure(config: ConfigureParams): void ### Description Synchronously configures the Google Sign-In module with client IDs and optional settings. Must be called before any other method. On Android, if no client ID is supplied the module falls back to auto-detecting `default_web_client_id` from the generated resources of `google-services.json`. On iOS, if neither `iosClientId` nor `webClientId` is provided, the module reads `CLIENT_ID` from the bundled `GoogleService-Info.plist`. ### Method `configure` ### Parameters #### Configuration Parameters - **webClientId** (string) - Optional - The web client ID for Android. If not provided, it attempts to auto-detect from `google-services.json`. - **iosClientId** (string) - Optional - The iOS OAuth client ID. If not provided, it attempts to read `CLIENT_ID` from `GoogleService-Info.plist`. - **scopes** (string[]) - Optional - An array of scopes to request during sign-in. Defaults to `['profile', 'email']`. - **offlineAccess** (boolean) - Optional - Set to `true` to receive a server auth code. Defaults to `false`. - **hostedDomain** (string) - Optional - Restricts sign-in to a specific G Suite domain. - **profileImageSize** (number) - Optional - The dimension in pixels for the user's profile photo. Defaults to 120. ### Request Example ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; // Typically called once in app bootstrap (e.g., App.tsx useEffect) RnGoogleSignin.configure({ // Android: Credential Manager uses the web client ID webClientId: '123456789-abc.apps.googleusercontent.com', // iOS: use the iOS OAuth client ID iosClientId: '123456789-xyz.apps.googleusercontent.com', // iOS-only extras scopes: ['profile', 'email'], // default scopes attached to every sign-in offlineAccess: false, // set true to receive serverAuthCode hostedDomain: 'yourcompany.com', // restrict to a G Suite domain profileImageSize: 120, // profile photo dimension in pixels }); // Minimal config — let auto-detection handle client IDs from config files RnGoogleSignin.configure({}); ``` ### Response This method does not return a value (`void`). Configuration is applied synchronously. ``` -------------------------------- ### Publish New Versions Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Uses release-it to handle version bumping, tag creation, and publishing to npm. ```sh yarn release ``` -------------------------------- ### Configuration Parameters Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Interface defining the parameters for configuring the Google Sign-In library. ```APIDOC interface ConfigureParams { webClientId?: string; // Web client ID androidClientId?: string; // Android client ID iosClientId?: string; // iOS client ID scopes?: string[]; // Initial scopes (iOS only) } ``` -------------------------------- ### Automatic Plugin Configuration Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Add the plugin to your app.json or app.config.js for automatic configuration. This is the recommended approach. ```json { "expo": { "plugins": [ "@novastera-oss/rn-google-signin" ] } } ``` -------------------------------- ### Configure React Native Google Sign-In Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Configure the library with your Google client IDs. Manual configuration is recommended for production. Automatic detection can be used as a fallback. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; // Manual configuration (recommended) RnGoogleSignin.configure({ webClientId: 'your-web-client-id.apps.googleusercontent.com', androidClientId: 'your-android-client-id.apps.googleusercontent.com', iosClientId: 'your-ios-client-id.apps.googleusercontent.com', }); // Automatic detection (fallback only) RnGoogleSignin.configure({}); ``` ```typescript RnGoogleSignin.configure({ // Android (Credential Manager uses Web client ID) webClientId: 'your-web-client-id.apps.googleusercontent.com', androidClientId: 'your-android-client-id.apps.googleusercontent.com', // optional alias // iOS iosClientId: 'your-ios-client-id.apps.googleusercontent.com', }); ``` -------------------------------- ### Build and Run Android App Source: https://github.com/darksorrow/rn-google-signin/blob/main/example/README.md Execute these commands in a new terminal window from your project root to build and run the Android application. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### Error Handling for Google Sign-In Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Demonstrates how to handle potential errors during the sign-in process using a try-catch block and a switch statement to differentiate error codes. This covers common issues like user cancellation, sign-in requirements, and network errors. ```typescript try { await RnGoogleSignin.signIn({}); } catch (error: any) { switch (error.code) { case 'sign_in_cancelled': // User cancelled break; case 'sign_in_required': // Sign in required (e.g. silent sign-in had no session) break; case 'no_credential': // Android: no Google account on device, or app not registered in Google Cloud (missing Android OAuth client with package name + SHA-1) break; case 'not_configured': // Not configured break; case 'network_error': // Network error break; default: console.error('Sign in error:', error); } } ``` -------------------------------- ### Run Unit Tests Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Executes the unit test suite using Jest. ```sh yarn test ``` -------------------------------- ### Basic Usage: Sign In and Sign Out Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Perform Google Sign-In and Sign-Out operations. Ensure parameters are always explicitly passed, even for default values, due to TurboModule requirements. ```typescript // Sign in try { const userInfo = await RnGoogleSignin.signIn({}); console.log('User info:', userInfo); } catch (error) { console.error('Sign in error:', error); } // Sign out await RnGoogleSignin.signOut(); ``` ```typescript // ✅ Correct - always pass the parameter await RnGoogleSignin.signIn({}); await RnGoogleSignin.hasPlayServices({}); // ❌ Incorrect - will cause runtime errors await RnGoogleSignin.signIn(); await RnGoogleSignin.hasPlayServices(); ``` -------------------------------- ### Manual Plugin Configuration with Custom Client IDs Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Configure the plugin manually in app.json or app.config.js if you need to specify custom client IDs for iOS, Android, or web. ```json { "expo": { "plugins": [ ["@novastera-oss/rn-google-signin", { "iosClientId": "your-ios-client-id.apps.googleusercontent.com", "androidClientId": "your-android-client-id.apps.googleusercontent.com", "webClientId": "your-web-client-id.apps.googleusercontent.com" }] ] } } ``` -------------------------------- ### Lint Project Files Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Runs ESLint to check for code style and potential errors. ```sh yarn lint ``` -------------------------------- ### Expo Configuration for Google Sign-In Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Configure the Expo project to use the Google Sign-In library. Ensure configuration files are placed in the project root and referenced in app.json. ```json { "expo": { "plugins": [ "@novastera-oss/rn-google-signin" ] } } ``` ```json { "expo": { "ios": { "googleServicesFile": "./GoogleService-Info.plist" }, "android": { "googleServicesFile": "./google-services.json" }, "plugins": [ [ "@novastera-oss/rn-google-signin", ] ] } } ``` -------------------------------- ### Type Check Project Files Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Runs TypeScript to verify the type safety of the project's code. ```sh yarn typecheck ``` -------------------------------- ### Verify New Architecture Confirmation Source: https://github.com/darksorrow/rn-google-signin/blob/main/CONTRIBUTING.md Check Metro logs for this message to confirm the app is running with the new architecture. Note the 'fabric':true and 'concurrentRoot':true properties. ```sh Running "RnGoogleSigninExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1} ``` -------------------------------- ### Enable New Architecture for iOS and Android Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Enables the New Architecture for React Native. For iOS, this is done via a command in the `ios` directory. For Android, it requires adding a property to `android/gradle.properties`. ```bash # iOS cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install # Android - Add to android/gradle.properties newArchEnabled=true ``` -------------------------------- ### Configure Google Sign-In Module Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Configure the Google Sign-In module with client IDs and optional settings. This must be called before any other method. On Android, it falls back to auto-detecting 'default_web_client_id' from 'google-services.json' if no client ID is supplied. On iOS, it reads 'CLIENT_ID' from 'GoogleService-Info.plist' if neither 'iosClientId' nor 'webClientId' is provided. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; // Typically called once in app bootstrap (e.g., App.tsx useEffect) RnGoogleSignin.configure({ // Android: Credential Manager uses the web client ID webClientId: '123456789-abc.apps.googleusercontent.com', // iOS: use the iOS OAuth client ID iosClientId: '123456789-xyz.apps.googleusercontent.com', // iOS-only extras scopes: ['profile', 'email'], // default scopes attached to every sign-in offlineAccess: false, // set true to receive serverAuthCode hostedDomain: 'yourcompany.com', // restrict to a G Suite domain profileImageSize: 120, // profile photo dimension in pixels }); // Minimal config — let auto-detection handle client IDs from config files RnGoogleSignin.configure({}); ``` -------------------------------- ### Expo Config Plugin - Automatic Mode Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Configures the Expo build process automatically by reading `google-services.json` and `GoogleService-Info.plist` from the project root. ```json // app.json — Automatic mode (requires google-services.json / GoogleService-Info.plist at project root) { "expo": { "ios": { "googleServicesFile": "./GoogleService-Info.plist" }, "android": { "googleServicesFile": "./google-services.json" }, "plugins": [ "@novastera-oss/rn-google-signin" ] } } ``` -------------------------------- ### TypeScript Interface for Configure Parameters Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Defines the parameters accepted by the configure function, including client IDs for web, Android, and iOS, as well as initial scopes for iOS. ```typescript interface ConfigureParams { webClientId?: string; androidClientId?: string; iosClientId?: string; scopes?: string[]; } ``` -------------------------------- ### Expo Config Plugin Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Configuration options for the Expo config plugin, supporting automatic and manual modes for setting up Google Sign-In. ```APIDOC ## Expo Config Plugin ### Description The bundled Expo config plugin configures both platforms during `expo prebuild`. It supports two modes: **automatic** (reads `google-services.json` and `GoogleService-Info.plist`) and **manual** (adds only the iOS URL scheme). ### Automatic Mode Configuration #### Request Example ```json // app.json — Automatic mode (requires google-services.json / GoogleService-Info.plist at project root) { "expo": { "ios": { "googleServicesFile": "./GoogleService-Info.plist" }, "android": { "googleServicesFile": "./google-services.json" }, "plugins": [ "@novastera-oss/rn-google-signin" ] } } ``` ### Manual Mode Configuration #### Request Example ```json // app.json — Manual mode (provide iOS URL scheme explicitly, no Firebase files needed) { "expo": { "plugins": [ [ "@novastera-oss/rn-google-signin", { "iosUrlScheme": "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" } ] ] } } ``` ### Manual Mode with Full iOS Info.plist Configuration #### Request Example ```typescript // Manual full iOS Info.plist configuration alongside the plugin { "expo": { "ios": { "bundleIdentifier": "com.example.myapp", "infoPlist": { "GIDClientID": "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com", "CFBundleURLTypes": [ { "CFBundleURLSchemes": [ "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" ] } ] } }, "plugins": [ [ "@novastera-oss/rn-google-signin", { "iosUrlScheme": "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" } ] ] } } ``` ``` -------------------------------- ### signOut Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Signs the user out of their Google account. Requires an empty object as a parameter due to TurboModule requirements. ```APIDOC ## signOut ### Description Signs the user out of their Google account. Requires an empty object as a parameter due to TurboModule requirements. ### Method `RnGoogleSignin.signOut()` ### Parameters This method does not accept any parameters. ### Request Example ```typescript await RnGoogleSignin.signOut(); ``` ``` -------------------------------- ### `signInSilently(): Promise` Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Attempts to restore a previous sign-in session without showing any UI. On Android it uses `setFilterByAuthorizedAccounts(true)` with `setAutoSelectEnabled(true)` via Credential Manager. On iOS it calls `restorePreviousSignIn` on `GIDSignIn`. Rejects with `sign_in_required` when no prior session exists. ```APIDOC ## `signInSilently(): Promise` ### Description Attempts to restore a previous sign-in session without showing any UI. On Android it uses `setFilterByAuthorizedAccounts(true)` with `setAutoSelectEnabled(true)` via Credential Manager. On iOS it calls `restorePreviousSignIn` on `GIDSignIn`. Rejects with `sign_in_required` when no prior session exists. ### Parameters None ### Request Example ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; async function restoreSession() { try { const result = await RnGoogleSignin.signInSilently(); console.log('Restored session for:', result.user.email); return result; } catch (error: any) { if (error.code === 'sign_in_required') { return null; } throw error; } } ``` ### Response #### Success Response (200) - **user** (object) - User profile information (same shape as `signIn` response). - **scopes** (string[]) - Array of granted OAuth scopes. - **idToken** (string) - The ID token for authentication. - **serverAuthCode** (string | null) - Server authorization code (if requested). #### Response Example ```json { "user": { "id": "1234567890", "name": "Jane Doe", "email": "jane@example.com", "photo": "https://lh3.googleusercontent.com/a/photo", "familyName": "Doe", "givenName": "Jane" }, "scopes": ["profile", "email", "openid"], "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6...", "serverAuthCode": null } ``` ### Error Handling - **sign_in_required**: No prior sign-in session exists. ``` -------------------------------- ### Expo Config Plugin - Manual iOS Info.plist Configuration Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Manually configures iOS `Info.plist` alongside the Expo config plugin, specifying the GIDClientID and URL schemes. ```json // Manual full iOS Info.plist configuration alongside the plugin { "expo": { "ios": { "bundleIdentifier": "com.example.myapp", "infoPlist": { "GIDClientID": "YOUR_IOS_CLIENT_ID.apps.googleusercontent.com", "CFBundleURLTypes": [ { "CFBundleURLSchemes": [ "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" ] } ] } }, "plugins": [ [ "@novastera-oss/rn-google-signin", { "iosUrlScheme": "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" } ] ] } } ``` -------------------------------- ### Full React Native Google Sign-In Component Source: https://context7.com/darksorrow/rn-google-signin/llms.txt A complete React Native component demonstrating the full authentication lifecycle, including configuration, silent sign-in, interactive sign-in, and sign-out. Ensure 'WEB_CLIENT_ID' and 'IOS_CLIENT_ID' are replaced with your actual Google Cloud project client IDs. ```typescript import React, { useEffect, useState } from 'react'; import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native'; import RnGoogleSignin from '@novastera-oss/rn-google-signin'; import type { User, GoogleSignInErrorCode } from '@novastera-oss/rn-google-signin'; export default function AuthScreen() { const [user, setUser] = useState(null); useEffect(() => { // 1. Configure once on mount RnGoogleSignin.configure({ webClientId: 'WEB_CLIENT_ID.apps.googleusercontent.com', iosClientId: 'IOS_CLIENT_ID.apps.googleusercontent.com', scopes: ['profile', 'email'], }); // 2. Attempt silent restore RnGoogleSignin.signInSilently() .then((result) => setUser(result.user)) .catch(() => {/* no previous session */}); }, []); const signIn = async () => { try { const result = await RnGoogleSignin.signIn({}); setUser(result.user); // Send result.idToken to your backend } catch (e: any) { const code: GoogleSignInErrorCode = e.code; if (code !== 'sign_in_cancelled') { Alert.alert('Sign-in failed', e.message); } } }; const signOut = async () => { await RnGoogleSignin.signOut(); setUser(null); }; const showTokens = async () => { const tokens = await RnGoogleSignin.getTokens(); Alert.alert('ID Token', tokens.idToken?.substring(0, 40) + '...'); }; return ( {user ? ( <> Welcome, {user.givenName}! {user.email} Get Tokens Sign Out ) : ( Sign In with Google )} ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12 }, welcome: { fontSize: 20, fontWeight: '600' }, btn: { padding: 14, borderRadius: 8, backgroundColor: '#4285f4' }, danger: { backgroundColor: '#db4437' }, }); ``` -------------------------------- ### Expo Config Plugin - Manual Mode Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Configures the Expo build process manually, providing the iOS URL scheme explicitly. No Firebase files are needed. ```json // app.json — Manual mode (provide iOS URL scheme explicitly, no Firebase files needed) { "expo": { "plugins": [ [ "@novastera-oss/rn-google-signin", { "iosUrlScheme": "com.googleusercontent.apps.YOUR_IOS_CLIENT_ID" } ] ] } } ``` -------------------------------- ### iOS GoogleService-Info.plist Location Source: https://github.com/darksorrow/rn-google-signin/blob/main/EXPO_PLUGIN.md Place the GoogleService-Info.plist file in the `ios/` directory of your Expo project for iOS configuration. ```treeview your-expo-project/ ├── ios/ │ └── GoogleService-Info.plist # Required for iOS ├── app.json └── ... ``` -------------------------------- ### Sign In with Google Account Picker Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Presents the Google account picker UI. Auto-generates a nonce on Android if not provided. Rejects concurrent sign-ins. Handles various error codes, including user cancellation and configuration issues. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; import type { SignInResponse, GoogleSignInErrorCode } from '@novastera-oss/rn-google-signin'; async function handleSignIn() { try { // Always pass an object — TurboModules require explicit parameters const result: SignInResponse = await RnGoogleSignin.signIn({ // nonce: 'custom-nonce-value', // optional; auto-generated if omitted // scopes: ['https://www.googleapis.com/auth/calendar'], // iOS only }); console.log('User ID: ', result.user.id); console.log('Name: ', result.user.name); console.log('Email: ', result.user.email); console.log('Photo: ', result.user.photo); console.log('ID Token: ', result.idToken?.substring(0, 30) + '...'); console.log('Scopes: ', result.scopes); // Send idToken to your backend for server-side verification await fetch('https://api.example.com/auth/google', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ idToken: result.idToken }), }); } catch (error: any) { const code: GoogleSignInErrorCode = error.code; switch (code) { case 'sign_in_cancelled': console.log('User cancelled'); break; case 'no_credential': // Android: no Google account on device or app not registered in Google Cloud console.error('No credential available — check Android OAuth client setup'); break; case 'not_configured': console.error('Call configure() before signIn()'); break; case 'network_error': console.error('Network unavailable'); break; case 'play_services_not_available': console.error('Google Play Services missing'); break; default: console.error('Sign-in error:', error.message); } } } ``` -------------------------------- ### Generate Android Signing Report Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Generates a signing report for your Android application. This is used to obtain the SHA-1 fingerprint required for Google Cloud Console configuration, especially for production APK builds. ```bash cd android && ./gradlew signingReport ``` -------------------------------- ### Expo Manual Mode Plugin Configuration Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Configure the rn-google-signin plugin in your app.json or app.config.js for manual mode. Ensure you provide the iosUrlScheme if not using client IDs directly in the plugin options. ```json { "expo": { "plugins": [ [ "@novastera-oss/rn-google-signin", { "iosUrlScheme": "com.googleusercontent.apps.your-ios-client-id" } ] ] } } ``` -------------------------------- ### Restore Previous Sign-In Session Silently Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Attempts to restore a previous sign-in session without UI. Uses Credential Manager on Android and GIDSignIn on iOS. Rejects with 'sign_in_required' if no prior session exists. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; async function restoreSession() { try { const result = await RnGoogleSignin.signInSilently(); console.log('Restored session for:', result.user.email); return result; } catch (error: any) { if (error.code === 'sign_in_required') { // No cached session — prompt the user with signIn() return null; } throw error; } } // Common pattern: silent restore on app launch, fallback to interactive async function initAuth() { const user = await restoreSession(); if (!user) { await handleSignIn(); // calls signIn({}) shown above } } ``` -------------------------------- ### hasPlayServices Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Checks if Google Play Services are available on the device. Requires an empty object as a parameter due to TurboModule requirements. ```APIDOC ## hasPlayServices ### Description Checks if Google Play Services are available on the device. Requires an empty object as a parameter due to TurboModule requirements. ### Method `RnGoogleSignin.hasPlayServices(params)` ### Parameters #### Request Body - **params** (object) - Required - Must be an empty object `{}`. ### Request Example ```typescript try { const hasServices = await RnGoogleSignin.hasPlayServices({}); console.log('Google Play Services available:', hasServices); } catch (error) { console.error('Error checking Play Services:', error); } ``` ### Response #### Success Response (200) - **hasServices** (boolean) - `true` if Google Play Services are available, `false` otherwise. ### Response Example ```json true ``` ``` -------------------------------- ### Add Internet and Network State Permissions for Android Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md These permissions are required for production APK builds of your Android app to ensure proper network communication for Google Sign-In. Add them to your `android/app/src/main/AndroidManifest.xml`. ```xml ``` -------------------------------- ### getTokens() Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Returns the current `idToken` and `accessToken` for the signed-in user. This is essential for making authenticated requests to Google APIs or other services. ```APIDOC ## `getTokens(): Promise` Returns the current `idToken` and `accessToken` for the signed-in user. On iOS it calls `refreshTokensIfNeededWithCompletion` to ensure the tokens are fresh before returning. On Android, since Credential Manager does not expose a separate access token, both `accessToken` and `idToken` are set to the same Google ID token value. ### Response Type Definition ```typescript interface GetTokensResponse { idToken?: string; accessToken?: string; } ``` ### Usage Example ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; import type { GetTokensResponse } from '@novastera-oss/rn-google-signin'; async function refreshAndUseTokens() { try { const tokens: GetTokensResponse = await RnGoogleSignin.getTokens(); console.log('ID Token (first 30):', tokens.idToken?.substring(0, 30)); console.log('Access Token (first 30):', tokens.accessToken?.substring(0, 30)); // Note: on Android accessToken === idToken (Credential Manager limitation) // Use the access token to call a Google API (iOS only has a distinct access token) const response = await fetch('https://www.googleapis.com/oauth2/v1/userinfo', { headers: { Authorization: `Bearer ${tokens.accessToken}` }, }); const profile = await response.json(); console.log('Google profile:', profile); } catch (error: any) { if (error.code === 'sign_in_required') { console.log('No user signed in — call signIn() first'); } else { console.error('getTokens failed:', error.message); } } } ``` ``` -------------------------------- ### TypeScript Interface for Sign In Response Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Defines the structure of the response object from the signIn method, containing the user details, scopes, and optional server authentication code or ID token. ```typescript interface SignInResponse { user: User; scopes: string[]; serverAuthCode?: string; idToken?: string; } ``` -------------------------------- ### Sign Out User with RN Google Sign-In Source: https://context7.com/darksorrow/rn-google-signin/llms.txt Signs the current user out and clears cached credentials. Use this to end a user's session. ```typescript import RnGoogleSignin from '@novastera-oss/rn-google-signin'; async function handleSignOut() { try { await RnGoogleSignin.signOut(); console.log('Signed out successfully'); // Clear your local app state here } catch (error: any) { console.error('Sign out failed:', error.message); } } ``` -------------------------------- ### TypeScript Interface for User Object Source: https://github.com/darksorrow/rn-google-signin/blob/main/README.md Defines the structure of the User object returned after a successful sign-in, including essential details like ID, name, email, and optional profile information. ```typescript interface User { id: string; name: string; email: string; photo?: string; familyName?: string; givenName?: string; } ```