Sign-in flows
All methods are static on GoogleSignIn. Call configure once before any other method.
import { getGoogleSignInErrorCode, GoogleSignIn, isSignInSuccess } from 'nitro-google-signin'
// Client IDs come from Info.plist and the default_web_client_id resource.
GoogleSignIn.configure({ requestOfflineAccess: true })
// At launch: the stored user, available synchronously on both platforms.
const user = GoogleSignIn.getCurrentUser()
// From a "Sign in with Google" button.
const result = await GoogleSignIn.presentExplicitSignIn()
if (isSignInSuccess(result)) {
await sendToBackend(result.session.idToken, result.session.serverAuthCode)
} else if (result.type === 'cancelled') {
// The user closed the sheet.
}
Pick a flow
| Method | Use it for | Android | iOS |
|---|---|---|---|
signIn() | Returning users | Accounts that already authorized the app. enableAutoSelect skips the sheet for one account. | Restores the previous sign-in without UI. |
createAccount() | Any account on the device | Every Google account, including ones that never used the app. | Interactive sign-in. |
presentExplicitSignIn() | A "Sign in with Google" button | Google's account dialog. | Interactive sign-in. |
signInWithGoogle() chains the first and last: it tries signIn() and falls back to presentExplicitSignIn() only on noSavedCredential.
Results, not exceptions
Sign-in methods resolve a SignInResult:
type | Meaning |
|---|---|
success | The user signed in; session is set. |
cancelled | The user dismissed the sign-in UI. |
noSavedCredential | No account has authorized this app yet, or no previous sign-in can be restored. |
Only real failures reject. Narrow a result with isSignInSuccess to get a typed session.
One flow at a time
Sign-in methods and requestScopes run one at a time. A call made while another is running rejects with IN_PROGRESS; on Android the ID token refresh inside getTokens() counts as a sign-in flow too. Disable your button while a flow runs, as the example button does.
Sign out or revoke
await GoogleSignIn.signOut() // the grant stays; signIn() can restore the account
await GoogleSignIn.revokeAccess() // revokes every granted scope and signs out
revokeAccess() rejects with SIGN_IN_REQUIRED without a signed-in user.
Play services on Android
await GoogleSignIn.checkPlayServices() // shows Google's fix-up dialog by default
Rejects with PLAY_SERVICES_NOT_AVAILABLE when Play services are missing or outdated. Pass false to skip the resolution dialog. Always resolves on iOS.