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
OAuthError is not a class but an object with factory functions and a type guard. All OAuth-specific errors produced by the hook are plain Error instances with a name of "OAuthError" and a code property set to one of the OAuthErrorCode constants.
Use OAuthError.isOAuthError(error) to narrow an unknown error to the OAuthError type, then inspect error.code to determine what went wrong.
Import
OAuthError
OAuthError is an object containing factory functions and a type guard. There is no new OAuthError() constructor.
Type definition
OAuthError instance is a standard Error with:
nameset to"OAuthError"messageset to"<code> <description>"(e.g.,"OA001 The Popup Closed")codeset to one of theOAuthErrorCodevalues
OAuthError.isOAuthError
true when error is an Error instance with a valid code property matching one of the known OAuthErrorCode values. Use this before accessing error.code to avoid runtime errors when handling the onError callback.
OAuthErrorCode
OAuthErrorCode is a const object that maps error names to their string codes. The type OAuthErrorCode is the union of all its values.
Type definition
Error codes
| Constant | Code | Description |
|---|---|---|
OAuthErrorCode.POPUP_CLOSED | OA001 | The user closed the popup window before completing authentication. |
OAuthErrorCode.POPUP_BLOCKED | OA002 | The browser blocked the popup window. The user needs to allow popups for your site. |
OAuthErrorCode.STATE_MISMATCH | OA003 | The state parameter returned by GitHub does not match the original value. Possible CSRF attack. |
OAuthErrorCode.MISSING_CODE | OA004 | The authorization code was not present in GitHub’s redirect response. |
Usage example
Handling popup blocked
OA002 occurs when the browser blocks the popup. This typically happens when initiateGitHubLogin is not called directly from a user gesture (such as a click handler). Calling it inside a setTimeout, Promise, or other async callback after the user gesture may cause browsers to block the popup.
Always call
initiateGitHubLogin synchronously inside a click handler to ensure the browser treats it as a user-initiated popup.
