You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`useScriptGoogleSignIn()`{lang="ts"} returns the standard script context (`status`, `proxy`, `onLoaded`, …) plus three helpers that wrap the most common flows. Schema options passed to the composable are merged into every call so you don't have to repeat `clientId`, `loginUri`, `uxMode` etc.
Calls `google.accounts.id.initialize()`{lang="ts"} with schema options merged with `config`. Internally guarded so multiple calls (e.g. across navigations and component remounts) are safe; Google's API logs an error if `initialize()`{lang="ts"} runs again after a button has been rendered, so the helper only forwards the first call.
45
+
46
+
```ts
47
+
initialize({
48
+
callback: (response) => {
49
+
// verify response.credential server-side
50
+
}
51
+
})
52
+
```
53
+
54
+
### `renderButton(parent, config?)`{lang="ts"}
55
+
56
+
Renders the personalized button. Auto-initializes if needed and is safe to re-render on locale change or navigation.
Google may still fall back to the user's Google account language regardless of this option. This is a Google-side behavior and not configurable.
102
+
::
103
+
104
+
### Redirect UX mode
105
+
106
+
With `uxMode: 'redirect'`, Google **POSTs** the credential to your `loginUri` server endpoint as `application/x-www-form-urlencoded` (fields: `credential`, `g_csrf_token`, `select_by`, …). The credential does **not** appear as a URL fragment after the redirect; it travels in the POST body, which your server then handles before redirecting the browser.
107
+
108
+
If you need the credential client-side (e.g. SPA with a separate API), use `uxMode: 'popup'` with a `callback` instead.
In `popup` UX mode (the default), Google opens a popup that delivers the credential back to your page via `window.postMessage`. If your page sends a strict `Cross-Origin-Opener-Policy` header, the browser will block that message and the sign-in will appear to do nothing: the popup closes but no callback fires.
181
+
182
+
If you set COOP at all, use `same-origin-allow-popups`:
Pages without an explicit COOP header work by default. Redirect mode (`uxMode: 'redirect'`) and FedCM-only flows are unaffected.
195
+
89
196
## FedCM API Support
90
197
91
198
Enable Privacy Sandbox [FedCM API](https://developers.google.com/identity/gsi/web/guides/fedcm-migration) support for enhanced privacy. **FedCM adoption becomes mandatory in August 2025.**
@@ -204,30 +311,20 @@ The One Tap prompt provides a simplified sign-in experience:
Copy file name to clipboardExpand all lines: packages/script/src/registry-types.json
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -452,6 +452,11 @@
452
452
"name": "GoogleSignInOptions",
453
453
"kind": "const",
454
454
"code": "export const GoogleSignInOptions = object({\n /**\n * Your Google API client ID.\n * @example 'XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com'\n * @see https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid\n */\n clientId: string(),\n /**\n * Auto-select credentials when only one Google account is available.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#auto_select\n */\n autoSelect: optional(boolean()),\n /**\n * The context text for the One Tap prompt.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#context\n */\n context: optional(union([literal('signin'), literal('signup'), literal('use')])),\n /**\n * Enable FedCM (Federated Credential Management) API support. Mandatory from August 2025.\n * @see https://developers.google.com/identity/gsi/web/guides/fedcm-migration\n */\n useFedcmForPrompt: optional(boolean()),\n /**\n * Cancel the One Tap prompt if the user clicks outside.\n * @default true\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#cancel_on_tap_outside\n */\n cancelOnTapOutside: optional(boolean()),\n /**\n * The UX mode for the sign-in flow.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#ux_mode\n */\n uxMode: optional(union([literal('popup'), literal('redirect')])),\n /**\n * The URI to redirect to after sign-in when using redirect UX mode.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#login_uri\n */\n loginUri: optional(string()),\n /**\n * Enable Intelligent Tracking Prevention (ITP) support for Safari.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#itp_support\n */\n itpSupport: optional(boolean()),\n /**\n * Allowed parent origin(s) for iframe embedding.\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#allowed_parent_origin\n */\n allowedParentOrigin: optional(union([string(), array(string())])),\n /**\n * Restrict sign-in to a specific Google Workspace hosted domain.\n * @example 'example.com'\n * @see https://developers.google.com/identity/gsi/web/reference/js-reference#hd\n */\n hd: optional(string()),\n})"
455
+
},
456
+
{
457
+
"name": "GoogleSignInHelpers",
458
+
"kind": "interface",
459
+
"code": "export interface GoogleSignInHelpers {\n /**\n * Initialize Google Identity Services. Schema options are used as defaults;\n * pass a callback (and any other non-serializable config) here. Subsequent\n * calls are a no-op so this is safe to invoke from a remounting component.\n */\n initialize: (config?: Partial<IdConfiguration>) => void\n /**\n * Render a personalized Google Sign-In button. Auto-initializes if needed.\n * Safe to re-render on navigation or locale change.\n */\n renderButton: (parent: HTMLElement, config?: GsiButtonConfiguration) => void\n /**\n * Show the One Tap prompt. Auto-initializes if needed.\n */\n prompt: (listener?: (notification: MomentNotification) => void) => void\n}"
0 commit comments