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.
@react-oauth/github represents every OAuth failure as a plain Error object with a code property added. Four codes cover every failure mode the hook can produce.
Error codes
| Code | Constant | Description |
|---|---|---|
OA001 | OAuthErrorCode.POPUP_CLOSED | The user closed the popup window before completing authorization. |
OA002 | OAuthErrorCode.POPUP_BLOCKED | The browser blocked the popup window. |
OA003 | OAuthErrorCode.STATE_MISMATCH | The state parameter returned by GitHub did not match the value sent. Possible CSRF attack. |
OA004 | OAuthErrorCode.MISSING_CODE | The authorization code was not found in the OAuth callback URL. |
Error object structure
All OAuth errors are standardError instances extended with a code property:
error.name property is set to "OAuthError" and error.message contains a human-readable description like "OA001 The Popup Closed".
Checking for OAuth errors
UseOAuthError.isOAuthError() to distinguish OAuth-specific errors from unexpected runtime errors before checking the code:
Error instance, has a code property, and that code is one of the four known OAuthErrorCode values.
Complete switch-case example
Error-by-error guidance
OA001 — Popup closed
The user dismissed the popup before completing authorization. This is the most common “error” and often requires no action — the user simply changed their mind. Best practice: Clear any loading state silently. Only show a message if you want to offer a retry.OA002 — Popup blocked
The browser’s popup blocker prevented the window from opening. This happens when the login is not triggered directly by a user gesture (e.g., called in asetTimeout or useEffect rather than a click handler).
Best practice: Show a clear message asking the user to allow popups for your site and try again. Provide a retry button.
OA003 — State mismatch
Thestate value returned by GitHub does not match the one the hook sent. This indicates a possible CSRF attack or a browser extension interfering with the OAuth redirect.
Best practice: Treat this as a security-critical error. Show a generic “authentication failed” message. Do not expose technical details to the user.
OA004 — Missing code
GitHub’s callback URL did not contain acode parameter. This can happen if the user denied access, or if there is a misconfiguration in your OAuth App settings.
Best practice: Log the full error for debugging and show a retry option to the user.
