Quick start
Two helpers cover the common "sign in, send the token to your backend" flow:
import { getIdToken, GoogleSignIn, signInWithGoogle } from 'nitro-google-signin'
// Once at startup. Client IDs come from Info.plist and the default_web_client_id resource.
GoogleSignIn.configure()
// From your sign-in button.
const session = await signInWithGoogle() // undefined when the user cancels
if (session !== undefined) await sendToBackend(session.idToken)
// Later, for each authenticated request: a token valid for at least five more minutes.
const idToken = await getIdToken() // undefined when signed out
| Helper | Result |
|---|---|
signInWithGoogle() | One-call sign-in: restores a returning user with signIn(), shows presentExplicitSignIn() only when there is no saved credential. Resolves the GoogleSession, or undefined when the user cancels. |
getIdToken() | getTokens().idToken, or undefined when no user is signed in. Other failures reject. |
Show the signed-in user at launch
getCurrentUser() is synchronous and reads the session stored on the device, so it works right after launch, offline too:
const user = GoogleSignIn.getCurrentUser()?.user
Verify the token on your backend
The ID token is a JWT issued for your Web application client ID. Verify its signature, aud and exp on the server, and key accounts on sub (GoogleUser.id), not the email. When you restrict sign-in with hostedDomain, check the hd claim too.
Next
- Add a branded sign-in button.
- Use the full sign-in API for flows the helpers do not cover.
- Handle errors by code.