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.
Overview
useGitHubLogin is a custom React hook that handles the full GitHub OAuth 2.0 Authorization Code flow. It opens a popup window, polls for the authorization code, verifies the CSRF state, and calls your callbacks when the flow completes or fails.
The hook uses a popup window with polling — it never redirects the main page. The authorization code returned by
onSuccess must be exchanged for an access token on your backend; never do this client-side.Usage
Options
Your GitHub OAuth App Client ID. You can find this in your GitHub Developer Settings under your OAuth App.
Callback called when authentication succeeds. Receives an
OAuthResponse object containing the authorization code and optional state.Callback called when authentication fails for any reason. The
error argument may be an OAuthError instance — use OAuthError.isOAuthError(error) to narrow the type and inspect the code property.The redirect URI registered in your GitHub OAuth App settings. Must match exactly what you configured in GitHub.
A space- or comma-separated list of OAuth scopes to request. See the common scopes section below.
Options for configuring the popup window size and position. See PopupWindowOptions below.
A custom CSRF state parameter. If you omit this, the hook auto-generates a random string. The state is verified when the OAuth callback returns — a mismatch triggers an
OAuthError with code OA003.When set to
false, passes allow_signup=false to GitHub’s authorize endpoint, preventing new users from creating a GitHub account during the OAuth flow.Optional callback called immediately when the OAuth flow is initiated, before the popup opens. Useful for analytics or to show a loading indicator before
isLoading is set.Return value
Call this function to start the OAuth flow. It opens the GitHub authorization popup and begins polling for the response. If a flow is already in progress, calling this again is a no-op.
true while the OAuth flow is in progress (from the moment the popup opens until onSuccess or onError is called). Use this to disable your login button and prevent duplicate requests.Types
UseGitHubLoginOptions
UseGitHubLoginReturn
OAuthResponse
The object passed to youronSuccess callback.
The authorization code returned by GitHub. Send this to your backend to exchange for an access token.
The CSRF state parameter echoed back by GitHub. The hook verifies this against the original state automatically.
Present when GitHub returns an error in the redirect URL (e.g.,
access_denied).Human-readable description of the error returned by GitHub, when present.
PopupWindowOptions
Common scopes
| Scope | Description |
|---|---|
user:email | Read the user’s email addresses. This is the default scope. |
repo | Full control of public and private repositories. |
read:org | Read organization and team membership. |
gist | Create and update gists. |
notifications | Access notifications. |
CSRF protection
The hook automatically generates a randomstate parameter for each OAuth flow and verifies it when GitHub redirects back. If the state does not match, onError is called with an OAuthError with code OA003.
You can provide your own state value for additional verification in onSuccess:

