GoogleSignIn
import { GoogleSignIn } from 'nitro-google-signin'
Signs users in with their Google account: Credential Manager on Android and the Google Sign-In SDK on iOS. All methods are static. Call configure once before any other method.
Failures reject with an Error whose message starts with a [CODE] tag; read it with getGoogleSignInErrorCode. Sign-in methods and requestScopes run one at a time; a call made while another runs rejects with IN_PROGRESS.
| Method | Returns |
|---|---|
configure(configuration?) | void |
checkPlayServices(showResolutionDialog?) | Promise<void> |
signIn() | Promise<SignInResult> |
createAccount() | Promise<SignInResult> |
presentExplicitSignIn() | Promise<SignInResult> |
requestScopes(scopes) | Promise<AuthorizationResult> |
getCurrentUser() | GoogleSession | undefined |
getTokens() | Promise<GoogleTokens> |
clearCachedAccessToken(accessToken) | Promise<void> |
signOut() | Promise<void> |
revokeAccess() | Promise<void> |
configure
static configure(configuration?: GoogleSignInConfiguration): void
Sets the OAuth clients and request options used by every later call. Call it again to change them. Client IDs left out are read from the native configuration; see GoogleSignInConfiguration.
Throws NOT_CONFIGURED when a client ID is empty or cannot be resolved.
checkPlayServices
static checkPlayServices(showResolutionDialog?: boolean): Promise<void>
Resolves when Google Play services can sign users in. Rejects with PLAY_SERVICES_NOT_AVAILABLE otherwise, after showing Google's resolution dialog when showResolutionDialog is true (the default) and the user can fix it. Always resolves on iOS.
signIn
static signIn(): Promise<SignInResult>
Signs in a returning user. Android shows the accounts that already authorized this app (enableAutoSelect skips the sheet for one account); iOS restores the previous sign-in without UI. Resolves noSavedCredential when there is none.
createAccount
static createAccount(): Promise<SignInResult>
Signs in with any Google account on the device, including accounts that never used this app.
presentExplicitSignIn
static presentExplicitSignIn(): Promise<SignInResult>
Runs the flow of a "Sign in with Google" button: Google's account dialog on Android and the interactive sign-in on iOS.
requestScopes
static requestScopes(scopes: string[]): Promise<AuthorizationResult>
Asks the signed-in user to grant more OAuth scopes, showing consent when needed. scopes are full OAuth scope URLs. Resolves an access token, the granted scopes and, with requestOfflineAccess, a server auth code.
Rejects with SIGN_IN_REQUIRED without a user and SIGN_IN_CANCELLED when the user declines. See Scopes and server auth codes.
getCurrentUser
static getCurrentUser(): GoogleSession | undefined
Returns the signed-in user, or undefined. Synchronous. Reads the session stored on the device, so it works right after launch and before configure. The returned session never contains a serverAuthCode.
getTokens
static getTokens(): Promise<GoogleTokens>
Returns an ID token valid for at least five more minutes and a fresh access token of the signed-in user. Rejects with SIGN_IN_REQUIRED without a user.
iOS refreshes both silently. Android can get a new ID token only from a sign-in: it runs Credential Manager's auto sign-in for the signed-in account, which shows Google's brief "Signing in as" bar, or the account sheet when Google cannot pick the account itself. That needs the app in the foreground (NO_PRESENTER otherwise), counts as a sign-in flow for IN_PROGRESS, and rejects with SIGN_IN_CANCELLED when the user dismisses the sheet.
clearCachedAccessToken
static clearCachedAccessToken(accessToken: string): Promise<void>
Discards a cached access token that Google rejected, so the next getTokens returns a new one. Resolves without doing anything when the token is not cached, including when no user is signed in.
signOut
static signOut(): Promise<void>
Signs the user out of this app. The account keeps its grant; signIn can restore it.
revokeAccess
static revokeAccess(): Promise<void>
Revokes every scope the signed-in user granted to this app and signs out. Rejects with SIGN_IN_REQUIRED without a user.