# Reference — react-native-nitro-google-signin

## Package

- **npm:** `react-native-nitro-google-signin`
- **peer:** `react-native-nitro-modules` ≥ 0.36 (required), `expo` (optional)
- **compatibility:** `compatibility.json` + [Compatibility guide](https://react-native-nitro-google-sign-in.github.io/docs/getting-started/compatibility)
- **platforms:** Android, iOS — no web, no Expo Go

## API

Full types: https://react-native-nitro-google-sign-in.github.io/docs/guide/api-reference

| Method                           | Description                                                                                          |
| -------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `configure(params)`              | Required first. `webClientId` string or `'autoDetect'`; iOS needs `iosClientId` or plist `CLIENT_ID` |
| `checkPlayServices(showDialog?)` | Android Play Services; iOS no-op                                                                     |
| `signIn()`                       | Android: authorized CredMan accounts; iOS: current user or restore                                   |
| `createAccount()`                | All accounts / interactive                                                                           |
| `presentExplicitSignIn()`        | Explicit Sign in with Google UI (Android dialog)                                                     |
| `requestScopes(scopes)`          | `{ accessToken, serverAuthCode }` after sign-in; **`offlineAccess: true` required only for non-null `serverAuthCode`** — use `accessToken` for on-device Google APIs |
| `getCurrentUser()`                 | Sync: current user + `scopes`, or `null`. Use before `requestScopes` to skip duplicate consent |
| `getTokens()`                      | `{ idToken, accessToken }` after sign-in; throws `SIGN_IN_REQUIRED` if not signed in |
| `clearCachedAccessToken(token)`    | Clears cached access token (Android) or marks session for refresh (iOS) |
| `signOut()`                      | iOS GIDSignOut; Android disables auto sign-in semantics                                              |
| `revokeAccess(id)`               | Android: revokes by email/id. iOS: current session only — throws if `id` does not match active user |

### Platform security notes

- **Backend:** Always verify `idToken` on your server (signature, `aud`, `iss`, `exp`). See repo `SECURITY.md`.
- **`hostedDomain`:** Validate JWT `hd` on backend. Android `buttonFlow` / `presentExplicitSignIn` validates `hd` after sign-in; Credential Manager flows filter at request time. iOS uses `GIDConfiguration.hostedDomain`.
- **`offlineAccess` + `signIn()`:** iOS silent restore returns `serverAuthCode: null` — use `createAccount()` for initial offline grant.
- **`serverAuthCode`:** Never log full codes in UI, analytics, or crash reporters.

### Types

`OneTapConfigureParams`, `OneTapResponse`, `OneTapResponseType`, `OneTapSuccessData`, `OneTapUser`, `OneTapAuthorizationResult`, `GetTokensResponse`, `OneTapResponseTypes`, `StatusCode`, `GoogleSignInButtonProps`, `GoogleSignInButtonSignInBehavior`, …

### Responses

`type`: `'success' | 'noSavedCredentialFound' | 'cancelled'` — `data` null unless success.

`OneTapUser.id` = stable Google account id (prefer over email).

Helpers: `isSuccessResponse`, `isNoSavedCredentialFoundResponse`, `isCancelledResponse`, `isErrorWithCode`, `statusCodes`, `GoogleSignInError`

### Button

`GoogleSignInButton`, `useGoogleSignInFromButton`, `GOOGLE_SIGN_IN_BUTTON_HEIGHT` (48), `GOOGLE_SIGN_IN_BUTTON_WIDTH` (`standard` 230 / `wide` 312 / `icon` 48), `signInBehavior`: `credentialManager` | `buttonFlow` | `none`

## Google Cloud & config files (bare + Expo)

OAuth clients, SHA-1, `google-services.json`, `GoogleService-Info.plist`, file paths:  
https://react-native-nitro-google-sign-in.github.io/docs/setup/google-cloud

## Expo {#expo}

```js
// app.config.js
plugins: ['react-native-nitro-google-signin'],
android: { googleServicesFile: './google-services.json', package: 'com.app' },
ios: { googleServicesFile: './GoogleService-Info.plist', bundleIdentifier: 'com.app' },
```

```bash
bunx expo prebuild --clean
bunx expo run:ios   # or android
```

Without Firebase plist/json:

```js
plugins: [
  [
    'react-native-nitro-google-signin',
    { iosUrlScheme: 'com.googleusercontent.apps.XXX' },
  ],
]
```

Use explicit `webClientId` on Android (no `google-services.json`).

**UIKit Scene Lifecycle (iOS 27 / Xcode 27):** For Expo SDK 57, configure `expo-build-properties` with `{ ios: { enableSceneSupport: true } }` to fix `UIApplicationEvaluateRuntimeIssueForNoSceneLifecycleAdoption` crash on launch (enabled by default in SDK 58+). Wire `GIDSignIn.sharedInstance.handle(url)` in `SceneDelegate.swift` (`scene(_:openURLContexts:)`).

## Android {#android}

**Credential Manager + GMS:** Library ships `androidx.credentials`, `credentials-play-services-auth`, `googleid`, `play-services-auth` — do not add duplicates unless you use Credential Manager for other providers. Play services on device required; call `checkPlayServices()`. Use **Web** client ID in `configure()`, not Android client ID.

**OAuth:** Android client with package name + SHA-1 (debug & release **and Play App Signing** for store builds). Missing Play signing SHA-1 often surfaces as `type: 'cancelled'` after account pick, not `DEVELOPER_ERROR`.

**Omit `google-services.json` + Gradle plugin** when using explicit `webClientId` (SHA-1 still required).

**autoDetect:** requires `google-services.json` in `android/app/` AND Gradle ([Android setup — update Gradle files](https://react-native-nitro-google-sign-in.github.io/docs/setup/android)):

```gradle
// android/build.gradle — buildscript.dependencies
classpath("com.google.gms:google-services:4.4.2") // 4.4.0+

// android/app/build.gradle — end of file
apply plugin: "com.google.gms.google-services"
```

**Explicit webClientId:** no `google-services.json`, no Gradle plugin — SHA-1 still required.

Expo: config plugin applies Gradle on `prebuild` when `googleServicesFile` is set.

**ProGuard / R8:** Library ships `android/consumer-rules.pro` (merged via `consumerProguardFiles`). No manual keeps for `androidx.credentials` / GMS. Do not add `-keep class androidx.**`. Test release builds after `minifyEnabled true`. [Android setup — ProGuard](https://react-native-nitro-google-sign-in.github.io/docs/setup/android#proguard-r8)

## iOS {#ios}

- Add `GoogleService-Info.plist` to target
- URL scheme: `REVERSED_CLIENT_ID` from plist
- Apps adopting UIKit scene lifecycle (Expo `enableSceneSupport` or bare `UISceneDelegate`): required `GIDSignIn.sharedInstance.handle(url)` in `SceneDelegate` `scene(_:openURLContexts:)` and `scene(_:willConnectTo:options:)`
- Bare RN without scenes: recommended `GIDSignIn.sharedInstance.handle(url)` in `AppDelegate` `application(_:open:options:)`; required if multiple `openURL` handlers

## Google Cloud

Create **Web**, **Android** (package + SHA-1), **iOS** (bundle ID) OAuth clients in one project.

## GoogleSignInButton

```tsx
<GoogleSignInButton
  signInBehavior="credentialManager"
  onSignInSuccess={(data) => {}}
  onSignInError={(e) => {}}
/>
```

`signInBehavior`: `credentialManager` | `buttonFlow` | `none`

## Do not

- Use Expo Go
- Skip native rebuild after install
- Omit `react-native-nitro-modules`
