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

@openai/auth-react

v0.1.0

Published

React components and session profile UI for Sign in with ChatGPT integrations

Readme

@openai/auth-react

Add Sign in with ChatGPT buttons and profile pictures to a React application. The package connects your auth integration to React components and hooks, with shared sign-in state, localized labels, and server-rendered button markup.

The package supports React 18 and 19. Your application supplies React and a matching renderer such as React DOM. For plain JavaScript, use @openai/auth.

Light and dark Sign in with ChatGPT buttons in outlined and contained variants.

Install

npm install @openai/auth @openai/auth-react

Use matching versions of both SDK packages. Your application supplies React 18 or 19 and a matching renderer such as React DOM. See the getting-started guide for authentication setup.

Add a sign-in button

import { ChatGPTAuthProvider, ChatGPTSignInButton } from '@openai/auth-react';

export function SignIn() {
  return (
    <ChatGPTAuthProvider options={{ authPath: '/auth/chatgpt' }}>
      <ChatGPTSignInButton width="full" />
    </ChatGPTAuthProvider>
  );
}

/auth/chatgpt must be a same-origin GET route in your application that starts sign-in. Replace it with your real route. Register an OAuth client for your application before connecting this route. Your backend or auth framework verifies the callback and tokens, then creates the application session.

If your auth framework uses a JavaScript function to start authentication, use options={{ adapter: chatgptAuth }} instead. The adapter guide and Next.js/Auth.js example explain how to build that integration.

Buttons inside one provider share an attempt, so clicking another button cannot start duplicate work. Render the provider inside your framework's client boundary when required. Server rendering produces a styled button that stays disabled until its client binding is ready.

Use an existing core client

Use client when your app already has a client shared with other views:

import { createChatGPTAuth } from '@openai/auth/client';
import { ChatGPTAuthProvider, ChatGPTSignInButton } from '@openai/auth-react';

const auth = createChatGPTAuth({ authPath: '/auth/chatgpt' });

export function SignIn() {
  return (
    <ChatGPTAuthProvider client={auth}>
      <ChatGPTSignInButton />
    </ChatGPTAuthProvider>
  );
}

Create the client once for the app's intended lifetime. In SSR applications, keep clients isolated per app/request. Creation does not start auth or session reads.

Supply exactly one of options or client. With options, the provider creates and destroys its client. With client, it removes only its own bindings and subscriptions on unmount. The app calls auth.destroy() after all consumers finish. React and DOM buttons attached to that client share one attempt and session source.

Button variants

Choose the surface, layout, and label independently:

| Prop | Values | Default | | ------------ | ------------------------------ | ---------- | | variant | outlined, contained | outlined | | layout | inline, spread | inline | | text | continue, sign-in, brand | continue | | appearance | light, dark, auto | auto | | size | standard, compact | standard | | width | content, full | content |

Render these buttons inside a provider:

<>
  <ChatGPTSignInButton width="full" />
  <ChatGPTSignInButton variant="contained" appearance="dark" text="sign-in" />
  <ChatGPTSignInButton layout="spread" text="brand" width="full" />
</>

inline centers the logo and label together. spread places the logo at the leading edge while keeping the label centered across the button. text="brand" displays ChatGPT with the full localized action as its accessible name. variant="button" is a deprecated alias for outlined.

Set locale to choose the label language. See localization for available languages and locale matching. Arabic, Persian, and Urdu use right-to-left layout, with the logo on the leading side. The SDK does not mirror the logo or end decoration.

Without locale, the mounted button uses <html lang> from its own document. It uses English if the document language does not identify a valid, supported locale. The button follows changes to <html lang>. An explicit locale overrides the document language. Remove locale to use the document language again. The SDK does not read browser language preferences.

Without locale, React uses English during server rendering (SSR) and initial hydration. It uses the document language after the button mounts. Pass the same explicit locale on the server and client to render translated labels immediately.

Display the signed-in profile

Add a session source to your adapter. Then render profile UI inside its provider:

import {
  ChatGPTAuthProvider,
  ChatGPTProfilePicture,
  ChatGPTSignInButton,
  useChatGPTProfile,
} from '@openai/auth-react';
import { chatgptAuth } from './chatgpt-auth';

function Account() {
  const profile = useChatGPTProfile();
  return (
    <>
      <ChatGPTProfilePicture size={40} />
      <span>{profile?.name ?? 'Account'}</span>
      <ChatGPTSignInButton />
    </>
  );
}

export function App() {
  return (
    <ChatGPTAuthProvider options={{ adapter: chatgptAuth }}>
      <Account />
    </ChatGPTAuthProvider>
  );
}

chatgptAuth is your application's adapter, not an SDK export. Its session.getSession({ signal }) reads your verified app session and returns { status: 'authenticated', profile } or { status: 'unauthenticated' }. The optional profile has { subject, name?, picture? }. Follow the session-source contract, or adapt the Auth.js implementation.

The provider observes the core client, which refreshes the profile on subscription, successful sign-in, source change notifications, and page focus/restoration. useChatGPTProfile() returns null when loading, when a profile is unavailable, or when the read fails. Use the core client's getSessionSnapshot() to distinguish those display states. Your auth framework remains responsible for authorization.

ChatGPTProfilePicture displays a neutral fallback while an image is loading, missing, or unavailable. Its empty default alt makes it decorative beside a visible account name. Supply meaningful alt text if the image identifies the account on its own. The component displays an existing session profile. It does not discover a ChatGPT account before sign-in.

To add a decorative profile picture inside the button:

<ChatGPTSignInButton layout="spread" width="full" endDecorator={<ChatGPTProfilePicture />} />

The decoration matches the logo size: 20 × 20px for standard buttons and 18 × 18px for compact buttons. An omitted or invalid profile size uses those dimensions inside the button and 20px outside it. An explicit valid size keeps its requested dimensions. CSS clips content that exceeds the slot. Default minimum heights remain 44px for standard buttons and 36px for compact buttons.

The wrapper hides the decoration from assistive technology and prevents focus and interaction. Keep essential account text, links, and controls outside the button.

The profile component still supports className and style overrides.

Styles and events

Default styles load automatically. Choose the SDK presets. Use className and style for placement and width only:

<ChatGPTSignInButton appearance="dark" width="full" style={{ marginBlock: 8 }} />

Keep the SDK's logo, light/dark palette, typography, and shape. The SDK rejects unsupported inline style keys, including fonts, colors, and custom properties. Host CSS must follow the same rules. Language font fallbacks and user accessibility settings remain supported. See the branding contract. For strict CSP, load @openai/auth-react/styles.css and set stylesheet="external" on the provider. React 18 with Trusted Types enforcement also needs external stylesheet mode. See CSP setup.

onClick, onFocus, and onBlur receive React synthetic events. Calling preventDefault() synchronously in onClick stops sign-in. The SDK controls the button's action label, logo, disabled state, and busy state. Use the supported accessibility props to associate help or errors. See the React API reference for refs, attributes, events, and lifecycle details.

Progress, errors, and retry

Use useChatGPTSignInState() inside the provider to display interaction progress. Handle onError in the provider's options configuration for application error UI. To allow another attempt without remounting buttons:

  1. Check the app session.
  2. Reconcile any external operation.
  3. Call the recovery function returned by useChatGPTSignInRecovery().

The state and recovery guide has complete recipes.

Interaction state is separate from the authenticated session. idle does not mean signed out. complete does not establish a session. Removing a component or resetting its interaction state does not cancel external authentication.

Learn more