npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xhub-ui/google-login-lite

v1.0.5

Published

Lightweight Google ID Login hook for React — returns credential (ID Token JWT) via google.accounts.id API

Readme

@xhub-ui/google-login-lite

Lightweight Google ID Login hook for React. Returns an ID Token (JWT) via the google.accounts.id API — no OAuth2 flows, no button components, just a login() function you wire to your own UI.

npm version License: MIT


Requirements


Installation

npm install @xhub-ui/google-login-lite
# or
yarn add @xhub-ui/google-login-lite

Quick Start

import {
  GoogleOAuthProvider,
  useGoogleIdLogin,
} from "@xhub-ui/google-login-lite";

function LoginButton() {
  const login = useGoogleIdLogin({
    onSuccess: (credentialResponse) => {
      // credentialResponse.credential is the ID Token JWT
      console.log("ID Token:", credentialResponse.credential);
    },
    onError: () => {
      console.error("Login failed");
    },
  });

  return <button onClick={login}>Sign in with Google</button>;
}

export default function App() {
  return (
    <GoogleOAuthProvider clientId="YOUR_CLIENT_ID">
      <LoginButton />
    </GoogleOAuthProvider>
  );
}

API

<GoogleOAuthProvider>

Wrap your app (or the subtree that needs Google login) with this provider. It loads the GSI script and makes clientId available to all hooks below it.

<GoogleOAuthProvider
  clientId="YOUR_CLIENT_ID"
  locale="en"
  onScriptLoadSuccess={() => console.log("GSI ready")}
  onScriptLoadError={() => console.error("GSI failed to load")}
>
  {children}
</GoogleOAuthProvider>

| Prop | Type | Required | Description | | --------------------- | ------------ | -------- | ---------------------------------------------------------- | | clientId | string | ✅ | Your Google OAuth 2.0 client ID | | nonce | string | — | Nonce applied to the GSI <script> tag | | locale | string | — | ISO-639 language code for the GSI UI (e.g. "en", "vi") | | onScriptLoadSuccess | () => void | — | Called when the GSI script loads successfully | | onScriptLoadError | () => void | — | Called when the GSI script fails to load | | children | ReactNode | ✅ | Your component tree |


useGoogleIdLogin(options)

Returns a login() function. Call it on a button click (or any user gesture) to trigger the Google One Tap / Sign In With Google prompt.

const login = useGoogleIdLogin({
  onSuccess, // required
  onError,
  hosted_domain,
  login_hint,
  nonce,
  auto_select,
  cancel_on_tap_outside,
  use_fedcm_for_prompt,
  use_fedcm_for_button,
  promptMomentNotification,
});

Options

| Option | Type | Default | Description | | -------------------------- | ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | onSuccess | (res: CredentialResponse) => void | — | Required. Called with the credential response on successful login | | onError | () => void | — | Called when login fails or no credential is returned | | promptMomentNotification | MomentListener | — | Callback for prompt moment notifications | | cancel_on_tap_outside | boolean | — | Cancel the prompt when the user clicks outside | | hosted_domain | string | — | Restrict sign-in to a specific G Suite domain (e.g. "yourcompany.com") | | use_fedcm_for_prompt | boolean | false | Use FedCM for the One Tap prompt | | use_fedcm_for_button | boolean | false | Use FedCM for the Sign In With Google button flow | | auto_select | boolean | — | Automatically select the account if only one session exists | | login_hint | string | — | Pre-fill the account selector with a specific email address | | nonce | string | — | Random string included in the ID token for replay protection |

CredentialResponse

The object passed to onSuccess:

| Field | Type | Description | | ------------ | -------- | ----------------------------------------------------------------- | | credential | string | The ID Token JWT — decode this on your backend to verify the user | | select_by | string | How the credential was selected ("user_1tap", "btn", etc.) | | clientId | string | The client ID that issued the credential |


useGoogleOAuth()

Low-level context hook. Use this if you need direct access to clientId or the script load state.

const { clientId, scriptLoadedSuccessfully } = useGoogleOAuth();

Must be used inside <GoogleOAuthProvider> — throws otherwise.


Exported Types

import type {
  CredentialResponse,
  GoogleCredentialResponse,
  IdConfiguration,
  MomentListener,
  PromptMomentNotification,
  UseGoogleIdLoginOptions,
} from "@xhub-ui/google-login-lite";

Examples

Restrict to a G Suite domain

const login = useGoogleIdLogin({
  hosted_domain: "yourcompany.com",
  onSuccess: (res) => console.log(res.credential),
});

Pre-fill a known email

const login = useGoogleIdLogin({
  login_hint: "[email protected]",
  onSuccess: (res) => console.log(res.credential),
});

Handle prompt moment notifications

const login = useGoogleIdLogin({
  onSuccess: (res) => console.log(res.credential),
  promptMomentNotification: (notification) => {
    if (notification.isNotDisplayed()) {
      console.warn("Prompt not shown:", notification.getNotDisplayedReason());
    }
    if (notification.isSkippedMoment()) {
      console.warn("Prompt skipped:", notification.getSkippedReason());
    }
  },
});

Verify the ID Token on your backend (Node.js example)

import { OAuth2Client } from "google-auth-library";

const client = new OAuth2Client(process.env.GOOGLE_CLIENT_ID);

async function verify(idToken: string) {
  const ticket = await client.verifyIdToken({
    idToken,
    audience: process.env.GOOGLE_CLIENT_ID,
  });
  return ticket.getPayload(); // { sub, email, name, picture, ... }
}

Migrating from @react-oauth/google

| @react-oauth/google | @xhub-ui/google-login-lite | | --------------------------------------- | ---------------------------------------------------- | | useGoogleLogin({ flow: 'implicit' }) | ❌ Not supported (OAuth2 flows removed) | | useGoogleLogin({ flow: 'auth-code' }) | ❌ Not supported | | useGoogleOneTapLogin | useGoogleIdLogin (manual trigger, not auto-prompt) | | GoogleLogin button component | ❌ Removed — bring your own button | | googleLogout | ❌ Removed | | hasGrantedAllScopesGoogle | ❌ Removed | | GoogleOAuthProvider | ✅ Same API | | CredentialResponse | ✅ Same type |

If you only need the ID Token (for "Sign in with Google" flows), the migration is a one-line hook swap.


License

MIT