Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/MomenSherif/react-oauth/llms.txt

Use this file to discover all available pages before exploring further.

The GoogleLogin component renders Google’s official branded button and handles the full sign-in flow. It supports popup and redirect modes, and renders the button using Google’s own GSI (Google Identity Services) SDK.

Basic usage

import { GoogleLogin } from '@react-oauth/google';

<GoogleLogin
  onSuccess={credentialResponse => {
    console.log(credentialResponse);
  }}
  onError={() => {
    console.log('Login failed');
  }}
/>
On success, onSuccess receives a CredentialResponse containing:
  • credential — a JWT ID token you can verify on your backend
  • clientId — the client ID used to sign in
  • select_by — how the credential was selected (e.g. btn, user_1tap, auto)

Button appearance

Use these props to control how the button looks.
{/* Standard button with text (default) */}
<GoogleLogin onSuccess={...} type="standard" />

{/* Icon-only button */}
<GoogleLogin onSuccess={...} type="icon" />
ValueDescription
standardFull button with Google logo and text (default)
iconGoogle logo only, no text

Width and logo alignment

<GoogleLogin
  onSuccess={...}
  width="300"
  logo_alignment="center"
/>
  • width — button width in pixels (string or number)
  • logo_alignment"left" (default) or "center"

Locale

The GoogleOAuthProvider locale prop controls the button language globally for all child components. The button language is automatically inherited from the provider — there is no per-button locale override on GoogleLogin itself.
<GoogleOAuthProvider clientId="YOUR_CLIENT_ID" locale="fr">
  {/* This button will render in French */}
  <GoogleLogin onSuccess={...} />
</GoogleOAuthProvider>

UX mode

By default, the button opens a popup window. You can switch to a full-page redirect instead.

Google Workspace

If your app is restricted to users from a specific Google Workspace organization, pass the domain via hosted_domain:
<GoogleLogin
  onSuccess={credentialResponse => {
    console.log(credentialResponse);
  }}
  hosted_domain="yourcompany.com"
/>
This hints to Google to show only accounts from that domain. You should still verify the hd claim in the ID token on your backend.

Full example

import { GoogleLogin } from '@react-oauth/google';

export function LoginPage() {
  return (
    <GoogleLogin
      onSuccess={credentialResponse => {
        // Send credentialResponse.credential (JWT) to your backend to verify
        fetch('/api/auth/google', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ credential: credentialResponse.credential }),
        });
      }}
      onError={() => {
        console.log('Login failed');
      }}
      theme="filled_blue"
      size="large"
      shape="pill"
      text="continue_with"
    />
  );
}

Build docs developers (and LLMs) love